Introns in Memory Mapped Files: A Tale of Junk Bytes and Memory Pages
A memory mapped files is virtual memory mapped to a physical file on disk, byte-by-byte. Or is it? Like with all advanced technology, the devil is in the detail...
Memory mapped files offer a number of benefits over traditional stream-based I/O. Advantages include random access performance, or the ability to share data across processes. The .NET framework provides built-in support for memory mapped files starting from version 4. In most cases using memory mapped files in .NET is as easy as using traditional file streams: just map a file into memory, open a seekable memory stream, and use it like a normal file while enjoying the performance benefits.
However, some tricky details lurk behind a corner: For instance - what are those weird bytes where an EOF was expected? Wanna know? Read on..