附加到 MemoryMappedFile?
也许我从根本上误解了内存映射文件如何工作的一些东西,但是,当我使用 MemoryMappedFile 时,如何附加到文件的末尾? CreateViewAccessor 只允许我创建文件当前容量的视图,
我可以使用底层 FileStream 写入末尾,但这不会违背使用 MemoryMapping 的目的吗? (我认为它也会缓存附加内容并将其写入磁盘)。另一种选择是缓存写入并从缓存中读取,而不是从内存流中读取附加数据。
只是想知道处理不断增长的内存映射文件的常见做法是什么,所以我不会再次重新发明轮子
Maybe I've misunderstood something fundamentally about how memory mapped files work but, how do I append to the end of a file when I'm using MemoryMappedFile? the CreateViewAccessor only allows me to create a view of the file current's capacity
I could write to the end using the underlying FileStream instead but doesn't that kind of defeat the purpose of using MemoryMapping? (I thought it would cache and write to disk the appending as well). Another option is to cache writes and read from the cache rather than the memory stream for appended data.
Just wondering what the common practice is for working with memory-mapped file's that's growing so I'm not reinventing the wheel yet again
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一旦创建了内存映射,就无法更改大小。
您可以在创建地图时指定尺寸。请参阅 http://msdn.microsoft.com/en-us/library/dd987389。 aspx
内存映射是某种高级 I/O 技术。除非 (1) 本机库需要它,否则不应使用它; (2) 在性能关键的环境中需要随机访问。无论哪种情况,您都不应该在不了解本机(机器级)含义的情况下使用它。
You cannot change the size once created the memory maps.
You can specify the size when creating the map. see http://msdn.microsoft.com/en-us/library/dd987389.aspx
Memory mapping is some kind of advanced i/o technique. You should not use it unless (1) it is required by native library; (2) you need random access in performance critical environment. In either case, you should not use it without understanding the native (machine-level) implication.