简体   繁体   English

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

[英]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.

相关问题 boost::interprocess memory 匿名段上的分配器 - boost::interprocess memory allocator on anonymous segment BOOST 1.73.0 进程间字符串分配器错误 - BOOST 1.73.0 Interprocess string allocator error boost ::进程间内存大小 - boost::interprocess memory size 包含字符串的结构的Boost进程间向量是否需要特殊的分配器? - Does Boost Interprocess vector of struct containing strings require special allocator? 在共享内存中使用boost :: interprocess allocator的std :: unordered_map - 缺点? - std::unordered_map with boost::interprocess allocator in shared memory - drawbacks? boost :: interprocess scoped_allocator AND容器的容器不在共享内存中 - boost::interprocess scoped_allocator AND Containers of containers NOT in shared memory 使用boost :: interprocess :: cached_node_allocator编译失败的boost :: unordered_map - boost::unordered_map using boost::interprocess::cached_node_allocator compilation failure 在 NFS 上查询 boost interprocess::file_lock - Query on boost interprocess::file_lock on NFS 避免使用boost :: interprocess :: message队列创建文件 - Avoid file creation with boost::interprocess::message queue boost iostream映射文件和boost进程间映射文件之间有区别吗? - Is there a difference between boost iostream mapped file and boost interprocess mapped file?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM