title: Storing dynamic length data 'inside' structure
body: <p><strong>Problem statement :</strong> User provides some data which I have to store inside a structure. This data which I receive come in a data structure which allows user to dynamically add data to it.</p>
  
  <p><strong>Requirement:</strong>  I need a way to store this data <em>'inside'</em> the structure, <em>contiguously</em>. </p>
  
  <p>eg. Suppose user can pass me strings which I have to store. So I wrote something like this :</p>
  
  <pre><code>void pushData( string userData )
  {
      struct 
      {
         string junk;
      } data;
  
      data.junk = userData;
  }
  </code></pre>
  
  <p><strong>Problem :</strong> When I do this kind of storage, actual data is not really stored 'inside' the structure because string is not POD. Similar problem comes when I receive vector or list.</p>
  
  <p>Then I could do something like this :</p>
  
  <pre><code>void pushData( string userData )
  {
      struct 
      {
         char junk[100];
      } data;    
  
      // Copy userdata into array junk
  }
  </code></pre>
  
  <p>This store the data 'inside' the structure, but then, I can't put an upper limit on the size of string user can provide. </p>
  
  <p>Can someone suggest some approach ?</p>
  
  <p>P.S. : I read something about serializability, but couldnt really make out clearly if it could be helpful in my case. If it is the way to go forward, can someone give idea how to proceed with it ?</p>
  
  <hr>
  
  <p>Edit : </p>
  
  <ol>
  <li>No this is not homework.</li>
  <li>I have written an implementation which can pass this kind of structure over message queues. It works fine with PODs, but I need to extend it to pass on dynamic data as well. </li>
  </ol>
  
  <p>This is how message queue takes data:</p>
  
  <p>i. Give it a pointer and tell the size till which it should read and transfer data.</p>
  
  <p>ii. For plain old data types, data is store inside the structure, I can easily pass on the pointer of this structure to message queue to other processes. </p>
  
  <p>iii. But in case of vector/string/list etc, actual data is not inside the structure and thus if I pass on the pointer of this structure, message queue will not really pass on the actual data, but rather the pointers which would be stored inside this structure.</p>
  
  <p>You can see <a href="https://stackoverflow.com/questions/1181816/how-to-receive-dynamic-length-data-from-a-message-queue">this</a> and <a href="https://stackoverflow.com/questions/13963653/ipc-message-queues-how-to-send-a-vector-of-pairs">this</a>. I am trying to achieve something similar.</p>