提升进程间分配器 - 管理文件大小

Dej*_*jwi 5 c++ boost-interprocess

首先,我将使用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);
Run Code Online (Sandbox Code Playgroud)

我不关心底层文件的最终大小,但我无法预见这个值.是否有任何增强机制,它将处理调整基础文件的大小?或者我必须抓住bip :: bad_alloc并自己照顾这个?

rod*_*igo 6

阅读本文档的这一部分.

你有grow()可能是你需要的静态成员函数:

bip::managed_mapped_file::grow("./file", extra_bytes);
Run Code Online (Sandbox Code Playgroud)

但你必须确保没有人使用该文件,这就是他们称之为离线增长的原因.根据问题,这可能是不可能的.