I couldn't find a sufficient example on how to use apache thrift for ipc-communication via shared memory. My goal is to serialize an exisiting class with help of thrift, then send via shared memory to a different process where i deserialize it again with help of thrift. Right now i'm using TMemoryBuffer and TBinaryProtocol to serialize the data. Although this works, I have no idea on how to write it to shared memory.

Here is my code so far:

#include "test_types.h"
#include "test_constants.h"
#include "thrift/protocol/TBinaryProtocol.h"
#include "thrift/transport/TBufferTransports.h"

int main(int argc, char** argv)
    int shID;
    char* myPtr;
    Person* dieter = new Person("Dieter", "Neuer");
    //Person* johann = new Person("Johann", "Liebert");
    //Car* ford = new Car("KLENW", 4, 4);

    PersonThrift dieterThrift;
    dieterThrift.nachName = dieter->getNachname();
    dieterThrift.vorName = dieter->getVorname();

    boost::shared_ptr<apache::thrift::transport::TMemoryBuffer> transport(new apache::thrift::transport::TMemoryBuffer);
    boost::shared_ptr<apache::thrift::protocol::TBinaryProtocol> protocol(new apache::thrift::protocol::TBinaryProtocol(transport));

    test thriftTest;

    u_int32_t size = thriftTest.write(protocol.get());

    std::cout << transport.get()->getBufferAsString();

    shID = shmget(1000, 100, IPC_CREAT | 0666);
    if (shID >= 0)
        myPtr = (char*)shmat(shID, 0, 0);

        if (myPtr==(char *)-1)
            //myPtr = protocol.get();
The main problem is the part

//myPtr = protocol.get();

How do I use thrift so that I can write my deserialized data into myPtr (and thus into shared memory). I guess TMemoryBuffer might already be a bad idea. As you may see, I'm not really experienced with this.

Kind regards and thanks in advance