InterprocessConnection and MemoryBlocks


Hi, I’m trying to send some data using an InterprocessConnection. The data is in an object that’s of a class I defined, lets call it DataObject.

To send the message, can I just say:

DataObject* dObj = new DataObject();

//populate dObj

MemoryBlock* mb = new MemoryBlock(dObj, sizeof(dObj));

then pass mb to sendMessage?

When it gets to the other side, how do I get the data out of it in the form of a DataObject? Should the following do the trick?

DataObject* dObj = (DataObject*)(mb.getData());

I know the doc mentions that the pointer will become invalid when the MemoryBlock is resized, it will also become invalid when we leave the messageRecieved() function, right?



Well I guess you could do that if the object is just a very simple structure, but obviously it’s not good c++ to bypass the normal constructors, etc. And you’re relying on having exactly the same memory structure at either end of the link.

It’s a lot cleaner (but slower) to do something like turn your object into XML and send that across.