3
我想要做的是有一個應用程序發送應用程序B指向一個對象已分配共享內存(使用boost :: interprocess)。對於那個指針傳輸,我打算使用boost::interprocess::message_queue
。很明顯,A中的直接原始指針在B中無效,所以我嘗試傳輸在共享內存上分配的offset_ptr
。但是,這似乎也不起作用。傳遞一個指針通過boost :: interprocess :: message_queue
進程A做到這一點:
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);
進程B做到這一點:
// 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);
在我看來,以這種方式做偏移指針,無效他在過程中有點副本B.我如何做到這一點?