dotnet / dotnet-api-docs

.NET API reference documentation (.NET 5+, .NET Core, .NET Framework)
https://docs.microsoft.com/dotnet/api/
Other
704 stars 1.55k forks source link

No coverage of how AllocHGlobal works under Linux. Documentation implies it is supported under Windows only. #10398

Open logical-intent opened 1 week ago

logical-intent commented 1 week ago

Type of issue

Outdated article

Description

[Enter feedback here] The documentation here says "This method exposes the Win32 LocalAlloc function from Kernel32.dll." I haven't tried using it under Linux but Copilot reckons it uses malloc there, so either it's hallucinating or this documentation is badly misleading and out of date.

Page URL

https://learn.microsoft.com/en-us/dotnet/api/system.runtime.interopservices.marshal.allochglobal?view=net-8.0

Content source URL

https://github.com/dotnet/dotnet-api-docs/blob/main/xml/System.Runtime.InteropServices/Marshal.xml

Document Version Independent Id

53418d00-f1c2-5cde-3843-b607b1dcf240

Article author

@dotnet-bot

karakasa commented 2 days ago

just fyi, under Unix-like systems, the method is implemented by NativeMemory.Alloc, essentially malloc.

https://github.com/dotnet/runtime/blob/128fdfd1fd982e277e969d5c7ca1710345f4f649/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.Unix.cs#L59-L62

https://github.com/dotnet/runtime/blob/128fdfd1fd982e277e969d5c7ca1710345f4f649/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/NativeMemory.Unix.cs#L126-L137