title: Memory layout of a .NET array
body: <p>What is the memory layout of a .NET array?</p>
  
  <p>Take for instance this array:</p>
  
  <pre><code>Int32[] x = new Int32[10];
  </code></pre>
  
  <p>I understand that the bulk of the array is like this:</p>
  
  <pre><code>0000111122223333444455556666777788889999
  </code></pre>
  
  <p>Where each character is one byte, and the digits corresponds to indices into the array.</p>
  
  <p>Additionally, I know that there is a type reference, and a syncblock-index for all objects, so the above can be adjusted to this:</p>
  
  <pre><code>ttttssss0000111122223333444455556666777788889999
          ^
          +- object reference points here
  </code></pre>
  
  <p>Additionally, the length of the array needs to be stored, so perhaps this is more correct:</p>
  
  <pre><code>ttttssssllll0000111122223333444455556666777788889999
          ^
          +- object reference points here
  </code></pre>
  
  <p>Is this complete? Are there more data in an array?</p>
  
  <p>The reason I'm asking is that we're trying to estimate how much memory a couple of different in-memory representations of a rather large data corpus will take and the size of the arrays varies quite a bit, so the overhead might have a large impact in one solution, but perhaps not so much in the other.</p>
  
  <p>So basically, for an array, how much overhead is there, that is basically my question.</p>
  
  <p>And before the <em>arrays are bad</em> squad wakes up, this part of the solution is a static build-once-reference-often type of thing so using growable lists is not necessary here.</p>