A read-only MemoryManager class. #106606
-
When I created the
For the case of unmanaged memory, it wouldn't make sense to create an instance of However, for buffer managed memory, it should be entirely possible, but I couldn't achieve a satisfactory implementation, mainly due to two scenarios:
When a For the buffer based on I considered finding a way to create memory using the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Note that MemoryManager does add rather unpleasant overhead that may not be suitable for something as performance-critical as a string primitive. After extensively evaluating all alternatives, I had to settle on Memory-like layout of byte[] + offset + length in U8String: https://github.com/U8String/U8String/blob/main/Sources/U8String/U8String.cs#L83-L84 It makes it easy to create Once you have this building block, it becomes a non-issue to provide convenient API for pinning, marshalling, etc. Much like |
Beta Was this translation helpful? Give feedback.
Note that MemoryManager does add rather unpleasant overhead that may not be suitable for something as performance-critical as a string primitive. After extensively evaluating all alternatives, I had to settle on Memory-like layout of byte[] + offset + length in U8String: https://github.com/U8String/U8String/blob/main/Sources/U8String/U8String.cs#L83-L84
It makes it easy to create
ROM<byte>
instances (you can even bitcast into them, though I'm feeling on the fence about it as it's UB which is not desirable) and works pretty well after struct handling improvements in .NET 8.Once you have this building block, it becomes a non-issue to provide convenient API for pinning, marshalling, etc.
Mu…