-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[API Proposal]: Int128 IPAddress.GetAddress() #83971
Comments
Tagging subscribers to this area: @dotnet/ncl Issue DetailsBackground and motivationEvery call to API ProposalThe property name to be defined. namespace System.Net;
public class IPAddress
{
...
public Int128 FullAddress { get; set; }
} API Usagevar ipAddressV6 = IPAddress.Parse("::1");
Int128 fullAddressV6 = ipAddressV6.FullAddress
var ipAddressV4 = IPAddress.Parse("1.2.3.4");
Int128 fullAddressV4 = ipAddressV4.FullAddress Alternative DesignsNo simple alternative for this today. RisksAdding a new property should not be a high risk.
|
Could also be a |
It can be in addition to Int128. |
Quoting from #68328 (comment)
|
We also have If you need UInt128 value = default; // or Unsafe.SkipInit(out UInt128 value)
bool success = address.TryWriteBytes(MemoryMarshal.AsBytes(new Span<UInt128>(ref value)), out int bytesWritten); @NN--- have you considered using that method? |
@antonfirsov I see how it makes better compared to what we have today. |
This is the code generated for ; Int128 i = 1;
; a.TryWriteBytes(MemoryMarshal.AsBytes(new Span<Int128>(ref i)), out var written);
00007FFC357B4052 vmovdqu xmm0,xmmword ptr [rbp-68h]
00007FFC357B4057 vmovdqu xmmword ptr [rbp-88h],xmm0
00007FFC357B405F lea rdx,[rbp-88h]
00007FFC357B4066 lea rcx,[rbp-78h]
00007FFC357B406A call qword ptr [CLRStub[MethodDescPrestub]@00007FFC359C7B10 (07FFC359C7B10h)]
00007FFC357B4070 mov rcx,qword ptr [rbp-58h]
00007FFC357B4074 mov qword ptr [rbp-0A0h],rcx
00007FFC357B407B vmovdqu xmm0,xmmword ptr [rbp-78h]
00007FFC357B4080 vmovdqu xmmword ptr [rbp-98h],xmm0
00007FFC357B4088 mov rcx,qword ptr [rbp-0A0h]
00007FFC357B408F lea rdx,[rbp-98h]
00007FFC357B4096 lea r8,[rbp-18h]
00007FFC357B409A cmp dword ptr [rcx],ecx
00007FFC357B409C call qword ptr [CLRStub[MethodDescPrestub]@00007FFC359C7570 (07FFC359C7570h)] While returning Int128 is much simpler: ; Int128 i;
; i = myIPAddress.FullAddress;
00007FFC357B4081 lea rdx,[rbp-10h]
00007FFC357B4085 mov rcx,qword ptr [rbp-50h]
00007FFC357B4089 cmp dword ptr [rcx],ecx
00007FFC357B408B call qword ptr [CLRStub[MethodDescPrestub]@00007FFC359C73D8 (07FFC359C73D8h)] |
Does this lead to measurable performance issues in your application? If yes we need to see more details to make the cause for potential improvements.
That would penalize all instances of IPv4 The main reason for |
@wfurt any thoughts here? If there are no strong counter-arguments, I recommend to close this as wontfix, since |
Right now IPAddress stores an array of bytes which is GC object 16 bytes. It would be nice to have TryWriteBytes implemented closely as possible to simple Int128 return. Thanks. |
@NN--- is there any reason you prefer |
It seems that However, if this class is used for IPv6 address, there is always a heap allocation for |
I would probably stay with And yes, Related to #30797, some of the troubles comes from allocation and GC afterwards. If anything I feel we could make argument for making IPAddress bigger to avoid separate allocation. DualMode Socket is the default now and it would be commonly used even for IPv4 destinations IMHO e.g. it would become IPv4 mapped IPv6 and allocate. |
I'm closing this in favor of #84776, we don't need a new API. |
Background and motivation
Every call to
IPAddrses.GetAddressBytes()
allocates an array, while usingIPAddress.Address
only copiesint
.The type
System.Int128
can cover both IPv4 and IPv6 in a single call without GC pressure.API Proposal
The property name to be defined.
API Usage
Alternative Designs
No simple alternative for this today.
Risks
Adding a new property should not be a high risk.
The text was updated successfully, but these errors were encountered: