与平台无关的内存映射[文件] IO

发布于 2024-12-17 01:42:27 字数 591 浏览 5 评论 0原文

我花了一些时间研究我正在开发的应用程序的内存映射 IO。我有一些非常大(TB 级)的文件,我想将它们中的段映射到内存中,以进行读取和写入,从而最大限度地利用操作系统级缓存。我正在编写的软件需要在 Unix/Linux 和 Windows 下运行......性能至关重要。

我发现了 boost::iostreams::mapped_file_sourceboost::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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

红玫瑰 2024-12-24 01:42:27

查看 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

眉目亦如画i 2024-12-24 01:42:27

这个问题很老了,但在谷歌上排名最高。所以我会添加一些我知道的其他库。

mio
用于内存映射文件 IO 的跨平台 C++11 仅头文件库。

  • 看似简单明了,但可能会被抛弃。

llfio
P1031 C++ 标准的低级文件 I/O 和文件系统库。

  • 它似乎是所有 io 库之母。已通过同行评审(又称酷刑)。建议作为 C++ 标准库的补充。

我还可以保证 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.

  • Seems simple and straightforward, but potentially abandoned.

llfio
P1031 low level file i/o and filesystem library for the C++ standard.

  • The mother of all io libraries it seems. Has gone through boost peer review (aka torture). Is proposed as an addition to C++ standard library.

I can also vouch for boost::interprocess, I've used it to great effect in the past.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文