.NET 4.0 内存映射文件性能
我想知道是否有人尝试过新的 .NET 4.0 内存映射文件功能? 我知道它们和操作系统一样古老,但 .NET 中的本机处理是新的。
有没有人能够对此进行测试并谈论性能? 我对二进制文件随机部分的访问时间、写入速度等非常感兴趣。与本机 WinAPI MMF 的性能比较也很好。
谢谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
.NET 4.0 中的内存映射文件(在新的 System.IO.MemoryMappedFiles 命名空间中)只需包装内存映射文件的 Win32 API。
这意味着它们尽可能快。这与用于将 .NET 程序集加载到内存中的机制相同。
就实际计时数字而言,这将取决于 32 位与 64 位、您拥有多少内存、文件有多大、访问模式以及在很大程度上取决于物理磁盘硬件的类型。
参考:内存映射文件
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
在以下问题中,我对 MemoryMapped 文件与标准 IO 进行了性能测试:
使用内存映射的缺点文件
我无法找到任何适合我的目的的大缺点,内存映射文件的性能大约快 4 倍,在这个问题中,您可以找到一些关于这些文件的工作方式和内容的有趣提示帐户。
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.
在我的测试中,.NET 4.5 MMF 的性能约为本机 WinAPI 调用性能的 40%,即慢两倍多。
In my tests the performance of .NET 4.5 MMF was ~40% of performance of native WinAPI calls, i.e. more than twice slower.