我可以通过boost :: interprocess :: message_queue发送C ++类对象吗?

时间:2018-11-19 14:40:53

标签: c++ boost message-queue

如何通过boost::interprocess::message_queue发送c ++类对象?

有人可以将使用IPC数据作为类对象的boost::interprocess::message_queue共享IPC实现的示例代码吗?

1 个答案:

答案 0 :(得分:0)

How can i send c++ class object via boost::interprocess::message_queue?

//Class Defination
#define MQ_DATA             IPCMsg
class IPCMsg
{
public:
IPCMsg() { data = NULL; }
int len;
void* data;
};

// Initialize message Queue
mSendMq = new message_queue(OPEN_OR_CREATE, "MQ", 1024, sizeof(MQ_DATA));
mReceiveMq = new message_queue(OPEN_ONLY, "MQ");

// Send Data to message Queue
MQ_DATA* inData = new IPCMsg();
mSendMq->send(inData, sizeof(*inData), 0);

// Receive Data from message Queue
MQ_DATA* outdata = NULL;
mReceiveMq->receive(&outdata, sizeof(*outdata), 1024, priority);