boost 映射文件是 RAII 吗?
从我从文档中可以看出它们不是,另一方面 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看实现,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.