Migrating a pointer via boost :: interprocess :: message_queue

What I'm trying to do is an application. Send application B to the pointer to the object that A allocated in shared memory (using boost :: interprocess). For this passing pointer I intend to use boost::interprocess::message_queue. Obviously, the direct raw pointer from A is not valid in B, so I am trying to pass offset_ptrallocated in shared memory. However, this also does not work.

Process A does the following:

typedef offset_ptr<MyVector> MyVectorPtr;
MyVectorPtr * myvector;    
myvector = segment->construct<MyVectorPtr>( boost::interprocess::anonymous_instance )();

*myvector = segment->construct<MyVector>( boost::interprocess::anonymous_instance )
        (*alloc_inst_vec); ;

// myvector gets filled with data here

//Send on the message queue
mq->send(myvector, sizeof(MyVectorPtr), 0);

Process B does the following:

// Create a "buffer" on this side of the queue
MyVectorPtr * myvector; 
myvector = segment->construct<MyVectorPtr>( boost::interprocess::anonymous_instance )();
mq->receive( myvector, sizeof(MyVectorPtr), recvd_size, priority);

As I can see, in this way make a small copy of the offset pointer, which makes it invalid in process B. How do I do this correctly?

+3
source share
2 answers

, , boost.

0

, , offset_ptr , . offset_ptr , /, , , , , - , .

offset_ptr - " " . , , , , , , .

, , . nullptr, , offset_ptr, , 1 - , , .

0

Source: https://habr.com/ru/post/1783691/


All Articles