独立于平台的内存映射[文件] IO [英] Platform independent memory mapped [file] IO
问题描述
我花了一些时间来调查内存映射IO为我工作的应用程序。我有一些非常大(TB级)的文件,我想从它们映射段到内存中,为阅读和写作,最大限度地利用OS级缓存。我写需要软件在Unix / Linux和Windows工作...性能是至关重要的。
I've spent some time investigating memory mapped IO for an application I'm working on. I have some very large (TB scale) files, and I want to map segments from them into memory, for both reading and writing, making maximum use of OS-level caching. The software I'm writing needs to work under Unix/Linux and Windows... performance is critical.
我发现的boost ::输入输出流:: mapped_file_source
和的boost ::输入输出流:: mapped_file_sink
,其中提供了大部分我在寻找的便利。我想,但没有发现这些设施有:
I've discovered boost::iostreams::mapped_file_source
and boost::iostreams::mapped_file_sink
, which provide most of the facilities I'm looking for. The facilities I'd like, but haven't found are:
- 强制写入的数据同步到磁盘(
则msync
(2)在Unix;FlushViewOfFile
在Windows上) - 文件prevent的锁定两个进程试图写入在同一时间在同一文件(或文件期间仍然被写入读..)
- 在创建时控制该文件的属性(UNIX)
- Forcing a synchronisation of written data to disk (
msync
(2) on Unix;FlushViewOfFile
on Windows) - Locking of files to prevent two processes attempting to write the same file at the same time (or read while the file is still being written..)
- Controlling attributes of the file at creation time (Unix)
我可以做这些事情使用提升/输入输出流/设备/ mapped_file.hpp
?有没有能更好地满足我的要求,其他独立于平台的库?我必须开发自己的跨平台库来获得这种灵活性?
Can I do these things using "boost/iostreams/device/mapped_file.hpp"
? Are there other platform independent libraries that would better suit my requirements? Must I develop my own cross-platform library to get this flexibility?
推荐答案
看的boost ::进程间和boost ::进程间:: file_mapping。他们有你需要的一切。
Look at boost::interprocess and boost::interprocess::file_mapping. They have everything you need.
这篇关于独立于平台的内存映射[文件] IO的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!