boost::interprocess container of pointers

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

Mateusz Ziobro escribió:
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.
If you store a offset_ptr in shared memory you can safely point to object constructed in that shared memory segment and that pointer will be dereferenced correctly in other processes. Another alternative is to use a handle_t integer to represent the shared address using //!Transforms previously obtained offset into an absolute address in the //!process space of the current process. Never throws.*/ void * get_address_from_handle (handle_t offset) const //!Transforms an absolute address into an offset from base address. //!The address must belong to the memory segment. Never throws. handle_t get_handle_from_address (const void *ptr) const http://www.boost.org/doc/libs/1_41_0/doc/html/interprocess/quick_guide.html#... The most usual method is to construct offset_ptrs in shared memory pointing to the allocated object. But in your case, since your object is a named object ("test_data_set"), other processes can just use managed_segment.find<TestDataSet>("test_data_set"); to obtain a valid address for its address space. Best, Ion
participants (2)
-
Ion Gaztañaga
-
Mateusz Ziobro