Hi,
I have a problem with container of pointers in shared memory using
boost::interprocess,
object created by construct method is mapped to local memory address, so
I can not just put it into
shared memory container because the address would be invalid in other
process,
probably I have to remap or use some kind of smart pointer and than put
into container.
My question is Does someone know how to do that? Please see following
piece of code.
#include <iostream>
#include
#include
#include
class TestData
{
int value_;
public:
TestData(int value): value_(value) { }
int get_value() const { return value_; }
};
int main(int argc)
{
using namespace boost::interprocess;
managed_shared_memory mgr(open_or_create, "shm_test", 1024*1024);
TestData* t1 = mgr.construct<TestData>("test_data")(99);
std::cout << t1->get_value() << std::endl;
//TestData* is address in local memory
//we can not keep those addresses in shared memory set, would be
invalid in other process
//typedef allocator allocator;
//typedef set, allocator>
TestDataSet;
//TestDataSet* s1 =
mgr.construct<TestDataSet>("test_data_set")(std::less(),
//
mgr.get_segment_manager());
}