如何声明一个boost :: circular_buffer以后再初始化?

时间:2017-08-18 19:55:25

标签: c++ boost memory-mapped-files circular-buffer boost-circularbuffer

我正在尝试在磁盘上使用循环缓冲区,但为了简化我的问题,我试图在不同的函数中使用循环缓冲区,而不必将循环缓冲区作为参数传递。所以它可能看起来像这样:

#include <boost/circular_buffer.hpp>
#include <boost/interprocess/allocators/allocator.hpp>
#include <boost/interprocess/managed_mapped_file.hpp>

struct debugStruct {
    int test1;
    char test2;
};

// declare the memory mapped file
boost::interprocess::managed_mapped_file mmf;

// declare the allocator
typedef boost::interprocess::allocator< debugStruct, boost::interprocess::managed_mapped_file::segment_manager > mmf_allocator;

// declare the circular buffer (this doesn't work)
boost::circular_buffer< debugStruct, mmf_allocator > mmf_buffer;

void initializeCB() {
    mmf = boost::interprocess::managed_mapped_file( boost::interprocess::open_or_create, "./testfile", 4ul << 20 );
    mmf_buffer = boost::circular_buffer< debugStruct, mmf_allocator >( 100, mmf.get_segment_manager() );
}

void doOperation() {
    struct debugStruct testStruct;
    mmf_buffer.push_back( testStruct );
}

谢谢!

0 个答案:

没有答案