问题
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!
回答1:
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
回答2:
In following question I made a performance test of MemoryMapped Files versus standard IO:
Disadvantages of using memory mapped files
I was not able to find nay big drawbacks for my purposes, the performance is about 4x faster for the memory mapped files and in the question you can find some interesting hints about the way these files works and what to have into account.
回答3:
In my tests the performance of .NET 4.5 MMF was ~40% of performance of native WinAPI calls, i.e. more than twice slower.
来源:https://stackoverflow.com/questions/2333075/net-4-0-memory-mapped-files-performance