[API Proposal]: Add some Memory API to do tricky mappings #110984
Labels
api-suggestion
Early API idea and discussion, it is NOT ready for implementation
area-System.Runtime
untriaged
New issue has not been triaged by the area owner
Background and motivation
Once upon a time I decided to implement the fastest
guncircular buffer on the wild West. I have found a tricky solution which maps two virtual pages to the same physical page. This thick virtually 'unwraps' the circular buffer over the page bounds. This leads to three and a half benefits:3.5. This is more SIMD friendly (I am not sure)
I can easily implement that trick in C++ using
mmap()
orVirtualAlloc()
. But it still seems impossible to me to implement it in C# without using P/Invoke or another kludges. I had an idea to use a memory mapped file and somehow pin it twice with (some help of unsafe sections), but it looks really clumsy.Maybe it is possible to implement in more elegant way, but I did not find any good ideas. (Or it is just googling skill issue)
I am open for discussion and hope this API would be helpful not only for circular buffers. I think I can implement this API by myself after we discuss the design of it.
API Proposal
I still have no idea of the best API design. But maybe something like that...
API Usage
Something like that
Alternative Designs
No response
Risks
It is difficult to me to predict some risks at this point. But I think there is a possible issues with JIT, GC or dotnet memory model.
The text was updated successfully, but these errors were encountered: