[英]Boost interprocess allocator - manage file size
At first I will outline the domain with source. 首先,我将使用source概述域。
namespace bip=boost::interprocess;
typedef bip::allocator<int, bip::managed_mapped_file::segment_manager> allocator;
typedef bip::vector<int, allocator> vector;
bip::managed_mapped_file m_file(open_or_create, "./file", constant_value);
bip::allocator alloc(m_file.get_segment_manager());
bip::vector *vec = m_file.find_or_construct<vector>("vector")(alloc);
I don't care about final size of an underlying file, but I cannot foresight this value. 我不关心底层文件的最终大小,但我无法预见这个值。 Is there any boost mechanism, which will handle resizing an underlying file? 是否有任何增强机制,它将处理调整基础文件的大小? Or I have to catch bip::bad_alloc and care about this by my own? 或者我必须抓住bip :: bad_alloc并自己照顾这个?
Read this this section of the docs. 阅读本文档的这一部分 。
You have the static member function grow()
that may be what you need: 你有可能是你需要的静态成员函数grow()
:
bip::managed_mapped_file::grow("./file", extra_bytes);
But you have to be sure that nobody is using the file, that's why they call it off-line growing . 但你必须确保没有人使用该文件,这就是他们称之为离线增长的原因 。 And that may not be possible depending on the problem. 根据问题,这可能是不可能的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.