title: Reading and writing to a buffer
body: <p>I have 2 classes, one that writes multiple 96bit objects to a buffer (32bits at a time - 3x int32), and one that i want to read from the same buffer.</p>
  
  <p>The first class (Writer) reserves and area of memory and creates a pointer to the first 32bit area.</p>
  
  <ol>
  <li><p>How do I write to the buffer safely (ignoring buffer overflow for now)... I need to write in 32bit chunks, so how do I change the position of the 'write pointer' between each 96bit write? Do I do something like:</p>
  
  <pre><code>for(int count = 0; count &lt; 100; ++count)  // for 100 96bit objects
  {
      for(int32 i = 0; i &lt; 3; ++i)
      {
          *buffer = *(myInt32 + i);
      }
      // ** how do I move the buffer ptr to the start of the next 96bit memory space? **
  }
  </code></pre></li>
  <li><p>Is it safe for me to reserve the memory, write a number of 96bit objects, then pass the pointer to the beginning of it to the second (Reader) class, to ensure they are both able to access the same objects?  (The Reader will read multiples of 96bit objects in one go (~10,000), so I only need to know the start of the data for reading.)</p></li>
  <li><p>Once the Reader has read the buffer, how do I 'reset' the pointer (empty the buffer) so that I can write to the buffer again?</p></li>
  </ol>
  
  <p><strong>The buffer:</strong>
  The buffer is actually a pointer to the beginning of an area of memory reserved by <code>posix_memalign</code>. </p>
  
  <pre><code>int32 *tempbufferPtr; 
  posix_memalign ((void**)&amp;tempbufferPtr, 8, 10000 ); // space for 10,000 objects 
  writePtr = (my96bitObjectclass*)tempbufferPtr;
  </code></pre>