I have the following data structure:

typedef struct
{
    short id;
    string name;
    short age;
} person_struct;

Using boost message queue, I tried to send this data structure to the message queue receiver in another process. However, after receiving, I have segmentation fault when accessing the 'name' variable in the above structure.

Below is my sender function:

person_struct MyRec;
MyRec.id = 1;
MyRec.name = "ABC123";
MyRec.age = 20;   
message_queue mqSender(create_only, "MSG_Q", 100, sizeof(person_struct));
mqSender.send(&MyRec, sizeof(person_struct), MQ_PRIORITY);

Below is my receiver function:

message_queue myReceiver(open_only, "MSG_Q");
person_struct *recvMsg = new person_struct();
size_t msg_size;
unsigned int priority;
myReceiver.receive(recvMsg, sizeof(person_struct), msg_size, priority);
cout << "ID: " << (*recvMsg).id << endl;
cout << "Name: " << (*recvMsg).name << endl;
cout << "Age: " << (*recvMsg).age << endl;

The cout for (*recvMsg).id is okay, but segmentation fault occurred at cout for (*recvMsg).name. Read somewhere that I need to do serialization for the structure, but can't figure out how to do it. Can anyone suggest?

Edit
Report