Open mjsabby opened 4 years ago
This has a lot of overlap with the existing MemoryMappedFile set of APIs. Would it make sense to piggy back on the existing APIs for this? E.g. https://docs.microsoft.com/en-us/dotnet/api/system.io.memorymappedfiles.memorymappedfilerights overlaps with MemoryProtection, etc.
@jkotas yes on both your comments. When you say piggy backing on the MemoryMappedFile set of APIs, are you proposing changing the namespace? I agree that the enums are valuable, but is there much more than that?
Perhaps you're thinking we could also support MAP_SHARED?
This functionality has large overlap with memory mapped files, so I do not see a problem with having it the same namespace as memory mapped files.
This is still open, but I want to throw another use case.
I am using VirtualAlloc by hand to generate executable code regions to which I can directly jump to. That use case doesn't really fit in 'memory mapped files'.
Background and Motivation
Marshal.AllocHGlobal
supports allocating native memory via C#. If a user wants to allocate native memory in a more specific way they have to write platform specific code that targets the underlyingVirtualAlloc
(on Windows) ormmap
on *nix API call.This is not ideal. While the code is not a lot, with proper error handling which are platform specific, not to mention a PInvokes in general is hard to get right with bitness, etc.
Proposed API
Usage Examples
Other thoughts
We would throw
PlatformNotSupportedException
where these options or capability is not supported.