title: Data buffering from a file. code not working as intended
body: <p>I am not very experienced in <code>C#</code>, but have lots of experience from other languages.</p>
  
  <p>I am doing a project in <code>C#</code> where I have to read and modify large files.
  For this I have coded a buffering scheme where I keep chunks of data in memory, and swap them to disk when I need to read more. I always eliminate the [0] element from the array, by moving the following elements back one position. </p>
  
  <pre><code>public struct TBBuffer
  {
      public long offset;
      public short[] data;
      public GCHandle dataHandle;
  }
  //tb is a TBBuffer[], the data[] is initialized to 4096.
  </code></pre>
  
  <p>If I use a small sample file, where everything fits in the buffers allocated, everything works as intended.</p>
  
  <p>Whenever I need to free up some memory for more data I do:</p>
  
  <pre><code>int bufIdx,bufNo;
  for (bufIdx = 0; bufIdx &lt; tb.buffer.Length - 1; bufIdx++)
  {
      tb.buffer[bufIdx] = tb.buffer[bufIdx + 1];
  }
  bufNo = tb.Length - 1;
  </code></pre>
  
  <p>I have determined that the above code is the source of the problem, but I am unable to find out why that is so.</p>
  
  <p>So my question is: Considering the <code>TBBuffer</code> struct, and its contents, does anybody have a clue why this is not working as expected ?</p>
  
  <p>Is there a more efficient way to do this.</p>