title: Is the 32-bit .NET max byte array size < 2GB?
body: <p>I have been looking at some SO questions related to the max size of an array of bytes (<a href="https://stackoverflow.com/questions/3944320/maximum-length-of-byte">here</a> and <a href="https://stackoverflow.com/questions/1730821/is-there-a-limit-of-elements-that-could-be-stored-in-a-list/1730836#1730836">here</a>) and have been playing with some arrays and getting some results I don't quite understand. My code is as follows:</p>
  <pre><code>byte[] myByteArr;
  byte[] myByteArr2 = new byte[671084476];
  
  for (int i = 1; i &lt; 2; i++)
  {
      myByteArr = new byte[671084476];
  }
  </code></pre>
  <p>This will compile and upon execution it will throw a <code>'System.OutOfMemoryException'</code> on the initialization of <code>myByteArr</code>. If I change the 2 in the for loop to a 1 or I comment out one of the initialization's (either <code>myByteArr2</code> or <code>myByteArr</code>) it will run fine.</p>
  <p>Also, <code>byte[] myByteArr = new byte[Int32.MaxValue - 56];</code> throws the same exception.</p>
  <p>Why does this happen when compiled for 32-bit? Aren't they within the 2GB limit?</p>