I'd like to know if anyone tried new .NET 4.0 Memory Mapped Files features? I know that they are as old as OS but native handling in .NET is new.
Has anyone been able to test this and say something about performance? I'm quite interested in access time to random parts of binary file, write speed and so on. Also performance comparsion to native WinAPI MMF would be nice.
Thanks!
Accessing memory mapped files is faster than using direct read and write operations for two reasons. Firstly, a system call is orders of magnitude slower than a simple change to a program's local memory.
But there are also disadvantages: An I/O error on a memory-mapped file cannot be caught and dealt with by SQLite. Instead, the I/O error causes a signal which, if not caught by the application, results in a program crash.
Memory-mapped I/O provides several potential advantages over explicit read/write I/O, especially for low latency devices: (1) It does not require a system call, (2) it incurs almost zero overhead for data in memory (I/O cache hits), and (3) it removes copies between kernel and user space.
A memory-mapped file contains the contents of a file in virtual memory. This mapping between a file and memory space enables an application, including multiple processes, to modify the file by reading and writing directly to the memory.
Memory mapped files in .NET 4.0 (in the new System.IO.MemoryMappedFiles
namespace) simply wrap the Win32 API for memory mapped files.
That means they are as fast as is possible. This is the same mechanism that is used to load .NET assemblies into memory.
In terms of actual timing numbers, this will depend on 32bit versus 64bit, how much memory you have, how large the files are, the access pattern(s) and to a large extent the type of physical disk hardware.
Ref: Memory-Mapped Files
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With