我想要做的是让应用程序 A 向应用程序 B 发送指向 A 已在共享内存上分配的对象的指针(使用 boost::interprocess )。对于该指针传输,我打算使用boost::interprocess::message_queue
. 显然,来自 A 的直接原始指针在 B 中无效,因此我尝试传输offset_ptr
在共享内存上分配的内存。然而,这似乎也不起作用。
进程 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中无效。我该怎么做呢?