title: Send complex data structure via boost message queue
body: <p>I have the following data structure:</p>
  
  <pre><code>typedef struct
  {
      short id;
      string name;
      short age;
  } person_struct;
  </code></pre>
  
  <p>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.</p>
  
  <p>Below is my sender function:</p>
  
  <pre><code>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(&amp;MyRec, sizeof(person_struct), MQ_PRIORITY);
  </code></pre>
  
  <p>Below is my receiver function:</p>
  
  <pre><code>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 &lt;&lt; "ID: " &lt;&lt; (*recvMsg).id &lt;&lt; endl;
  cout &lt;&lt; "Name: " &lt;&lt; (*recvMsg).name &lt;&lt; endl;
  cout &lt;&lt; "Age: " &lt;&lt; (*recvMsg).age &lt;&lt; endl;
  </code></pre>
  
  <p>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?</p>