Reputation: 261
Simply I am trying to create a circular buffer in shared memory and perform some insert and search operations in it.
So first I create my types:
typedef allocator<MyData, managed_shared_memory::segment_manager> ShmemAllocator;
typedef boost::circular_buffer<MyData,ShmemAllocator> cbMyDataContainerType;
Pointers to segment and container:
managed_shared_memory *segment;
cbMyDataContainerType *cbMyDataContainer;
I have created a shared memory succesfully before and I'm using it to share some other objects already, so here I find the previously created shared memory and try to create the Circular buffer:
segment = new managed_shared_memory(open_only, "MySharedMemory");
const ShmemAllocator alloc_inst (segment->get_segment_manager());
cbMyDataContainer = segment->construct<cbMyDataContainerType>
("MyDataContainerCircularBuffer")(alloc_inst), (CONTAINER_SIZE);
And try to insert some values here:
cbMyDataContainer->push_back(MyData(id, dataTime));
After that I try to dump to container like that:
int count = 0
for (cbMyDataContainerType::iterator it = cbMyDataContainer->begin(),
it_end = cbMyDataContainer->end(); it != it_end; ++it, count++)
{
std::cout << "Id : "<< it->id << " Time : " << it->dTime << std::endl;
}
But the problem is; while creating the container it seems that everything is ok (at least no exceptions) but it does not take the size (sizeof(cbMyContainer) seems 8 but CONTAINER_SIZE is 10000 so it should be smth like 8 * 10000 ?) and I can not insert any item on the container.
When I try to dump the container it does not even enter the for loop since there is no inserted item in it.
Do you have any idea about what is wrong here?
Thanks indeed...
Note: I am using Visual Studio 2008 VC++, Win7 x64
Upvotes: 3
Views: 2748
Reputation: 345
It been long time, but I think you should pass a size to circular buffer when construct it. Something like:
cbMyDataContainer = segment->construct<cbMyDataContainerType>
("MyDataContainerCircularBuffer")(CONTAINER_SIZE, alloc_inst);
Upvotes: 1