Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET 4.0 Memory Mapped Files Performance

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!

like image 750
michajas Avatar asked Feb 25 '10 09:02

michajas


People also ask

Are memory-mapped files faster?

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.

What are the disadvantages of memory-mapped IO?

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.

Why is memory-mapped IO faster?

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.

What are memory-mapped files used for in net?

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.


1 Answers

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

like image 122
Mitch Wheat Avatar answered Sep 19 '22 07:09

Mitch Wheat