0

I'm trying to use a circular buffer on disk, but to simplify my question I'm trying to use a circular buffer in different functions without having to pass the circular buffer as an argument. So it may look like this:

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

Thanks!

Carl Zhao
  • 21
  • 4

0 Answers0