boost 映射文件是 RAII 吗?

发布于 2024-12-03 06:03:25 字数 289 浏览 4 评论 0原文

从我从文档中可以看出它们不是,另一方面 RAII 是现代 cpp 的功能之一。

http://www.boost.org/doc /libs/1_47_0/libs/iostreams/doc/classes/mapped_file.html

编辑:事实证明答案是肯定的,但请不要忘记使用.is_open()。

From what I can tell from documentation they aren't, on the other hand RAII is the one of the features of modern cpp.

http://www.boost.org/doc/libs/1_47_0/libs/iostreams/doc/classes/mapped_file.html

EDIT: It turns out that the answer is yes, but please please dont forget to use .is_open().

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

梦回梦里 2024-12-10 06:03:25

查看实现,mapped_source/mapped_sink 都包含一个指向底层mapped_file_impl (请参阅此处的mapped_file_impl源代码)

如您所见,一旦最后一个引用被销毁,它就会调用析构函数,该析构函数从映射的文件。但是,它不会破坏映射文件,就像破坏 ofstream 会删除底层文件一样。

Looking at the implementation, the mapped_source/mapped_sink both contain a shared pointer to the underlying mapped_file_impl (See here for the mapped_file_impl source)

As you can see, once the last reference is destroyed, it calls the destructor which detaches from the mapped file. However, it does not destroy the mapped file, no more than destroying an ofstream deletes the underlying file.

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