【问题标题】:Boost interprocess allocator - manage file sizeBoost 进程间分配器 - 管理文件大小
【发布时间】:2013-04-03 16:56:20
【问题描述】:

首先我会用来源概述域。

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);

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

【问题讨论】:

    标签: c++ boost-interprocess


    【解决方案1】:

    阅读this section 的文档。

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

    bip::managed_mapped_file::grow("./file", extra_bytes);
    

    但您必须确保没有人在使用该文件,这就是为什么他们称其为离线增长。根据问题,这可能是不可能的。

    【讨论】:

    • 哦。很简单。我必须承认,在直接在 POSIX mmap 上解决了类似的挑战并使用了 Boost IOstreams 之后,我正在努力。参见例如这个答案how to swap one line with another in c++。我想知道他们是如何将其实现为可移植的。
    猜你喜欢
    • 2017-12-12
    • 1970-01-01
    • 2015-01-09
    • 2021-05-25
    • 1970-01-01
    • 1970-01-01
    • 2018-11-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多