logoalt Hacker News

SvenLyesterday at 10:37 PM1 replyview on HN

I think you don’t need to be unsafe, they have normal API for it.

https://learn.microsoft.com/en-us/dotnet/standard/io/memory-...


Replies

Const-metoday at 12:11 AM

Indeed, but these normal APIs have runtime costs for bounds checking. For some use cases, unsafe can be better. For instance, last time I used a memory-mapped file was for a large immutable Bloom filter. I knew the file should be exactly 4GB, validated that in the constructor, then when testing 12 bits from random location of the mapped file on each query, I opted for unsafe codes.

show 1 reply