c++ - How to declare a boost::circular_buffer to be initialized later? -
i'm trying use circular buffer on disk, simplify question i'm trying use circular buffer in different functions without having pass circular buffer argument. may 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 memory mapped file boost::interprocess::managed_mapped_file mmf; // declare allocator typedef boost::interprocess::allocator< debugstruct, boost::interprocess::managed_mapped_file::segment_manager > mmf_allocator; // declare 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!
Comments
Post a Comment