与平台无关的内存映射[文件] IO
我花了一些时间研究我正在开发的应用程序的内存映射 IO。我有一些非常大(TB 级)的文件,我想将它们中的段映射到内存中,以进行读取和写入,从而最大限度地利用操作系统级缓存。我正在编写的软件需要在 Unix/Linux 和 Windows 下运行......性能至关重要。
我发现了 boost::iostreams::mapped_file_source
和 boost::iostreams::mapped_file_sink
,它们提供了我正在寻找的大部分功能。我想要但尚未找到的功能包括:
- 强制将写入的数据同步到磁盘(Unix 上的
msync
(2);Windows 上的FlushViewOfFile
- )文件以防止两个进程尝试同时写入同一文件(或在文件仍在写入时读取......)
- 在创建时控制文件的属性(Unix)
我可以使用以下命令执行这些操作吗“boost/iostreams/device/mapped_file.hpp”
?是否有其他独立于平台的库更适合我的要求?我必须开发自己的跨平台库才能获得这种灵活性吗?
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.
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:
- 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)
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
查看 boost::interprocess 和 boost::interprocess::file_mapping。他们有你需要的一切。
boost::interprocess
boost::interprocess::file_mapping
Look at boost::interprocess and boost::interprocess::file_mapping. They have everything you need.
boost::interprocess
boost::interprocess::file_mapping
这个问题很老了,但在谷歌上排名最高。所以我会添加一些我知道的其他库。
mio
用于内存映射文件 IO 的跨平台 C++11 仅头文件库。
llfio
P1031 C++ 标准的低级文件 I/O 和文件系统库。
我还可以保证 boost::interprocess,我过去使用它取得了巨大的效果。
This question is pretty old but the top hit on google. So I'll add some other libs I know of.
mio
Cross-platform C++11 header-only library for memory mapped file IO.
llfio
P1031 low level file i/o and filesystem library for the C++ standard.
I can also vouch for boost::interprocess, I've used it to great effect in the past.