title: Max length for a dynamic array in Delphi?
body: <p>I was curious how long a dynamic array could be so I tried</p>
  
  <pre><code>SetLength(dynArray, High(Int64));
  </code></pre>
  
  <p>That has a value of 9,223,372,036,854,775,807 and I figure that would be the largest number of indexes I could reference anyway.  It gave me a:</p>
  
  <blockquote>
    <p>ERangeError with message 'Range check error'.</p>
  </blockquote>
  
  <p>So I tried:</p>
  
  <pre><code>SetLength(dynArray, MaxInt); 
  </code></pre>
  
  <p>and got the same error!</p>
  
  <p>Interestingly I could call it with</p>
  
  <pre><code>SetLength(dynArray, Trunc(Power(2, 32));
  </code></pre>
  
  <p>Which is actually twice the size of MaxInt!</p>
  
  <p>I tried </p>
  
  <pre><code>SetLength(dynArray, Trunc(Power(2, 63) - 1));
  </code></pre>
  
  <p>Which is the same as High(Int64), and that failed too. </p>
  
  <p>Short of continued trial and error, does someone know the maximum size?  Does it depend on the size of the elements in the array?</p>
  
  <p>I am using Delphi 2009.  Will it be different for different versions (obviously when Commadore comes out it should be greater!)</p>