Boost interprocess map in shared memory
Hallo, I have problem when using interprocess package from boost lib. I would like to have map object in memory. I created example files for creating and reading this object from shared memory. http://www.boost.org/doc/libs/1_35_0/doc/html/interprocess/quick_guide.html#... It is working ok. Now, I want to have library, where i want to find previously created shared segment and read it more-times. But I do not want to open it on every runQ function call. I need to open this segment only once and use it more-times when runQ in lib is called. I tried this: #include .... managed_shared_memory segment; int init() { managed_shared_memory localsegment(open_only, "MySharedMemory"); segment = localsegment; } int runQ() { mymap = segment.find<MyMap>("MyMap").first; work with mymap.... } But the declaration of "managed_shared_memory segment" raise error when compiling: /usr/local/include/boost-1_35/boost/interprocess/managed_shared_memory.hpp:61: error: ‘boost::interprocess::basic_managed_shared_memory<CharType, MemoryAlgorithm, IndexType>::basic_managed_shared_memory() [with CharType = char, AllocationAlgorithm = boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void>, 0u>, IndexType = boost::interprocess::iset_index]’ is private xqtrans.cpp:261: error: within this context How can use and assign segment globaly in my lib?? Thank you very much for any idea :-) Jan Suchy
Jan Suchý wrote:
Now, I want to have library, where i want to find previously created shared segment and read it more-times. But I do not want to open it on every runQ function call. I need to open this segment only once and use it more-times when runQ in lib is called.
I tried this:
The problem is that managed_shared_memory is not copyable. With current trunk code you could move it from localsegment to segment: managed_shared_memory localsegment(open_only, "MySharedMemory"); segment = move(localsegment); //localsegment is now in default-constructed state For 1.35 code allocate it through new (not compiled, this might contain errors): std::auto_ptr<managed_shared_memory> segment_ptr; int init() { segment_ptr.reset (new managed_shared_memory (open_only, "MySharedMemory") ); } Regards, Ion
participants (2)
-
Ion Gaztañaga
-
Jan Suchý