我正在尝试在磁盘上使用循环缓冲区,但为了简化我的问题,我试图在不同的函数中使用循环缓冲区,而不必将循环缓冲区作为参数传递。所以它可能看起来像这样:
#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 );
}
谢谢!