title: Can't create huge arrays
body: <p>Like many other programmers, I went into <a href="https://en.wikipedia.org/wiki/Prime_number" rel="nofollow noreferrer">primes</a>, and as many of them, what I like is the challenge, so I'm not looking for comment like <em>Atkin did this faster than you dude</em>, but just a solution - or at least an hint - to my issue.</p>
  <p>I need to create <strong>big</strong> arrays (like size &gt; <code>int.MaxValue</code>). So I went to a lot of web pages and found the <a href="https://msdn.microsoft.com/en-us/library/hh285054%28v=vs.110%29.aspx" rel="nofollow noreferrer">gcAllowVeryLargeObjects Element</a> one. I thought I was saved, add the following magic to my <code>App.config</code>:</p>
  <pre><code>&lt;configuration&gt;
    &lt;runtime&gt;
      &lt;gcAllowVeryLargeObjects enabled=&quot;true&quot; /&gt;
    &lt;/runtime&gt;
  &lt;/configuration&gt;
  </code></pre>
  <p>But it <em>didn't</em> work. Here's the code I use :</p>
  <pre><code>void go(object sender, EventArgs eventArgs)
  {
      t.Stop();
      ulong maxprime = 10;
      Stopwatch stopwatch = new Stopwatch();
      string s = String.Empty;
      while (maxprime &lt; ulong.MaxValue)
      {
          stopwatch.Restart();
          richTextBox2.Text += Environment.NewLine + (&quot;Max \t= &quot; + maxprime.ToString(&quot;N0&quot;));
          try
          {
              richTextBox2.Text += Environment.NewLine + (&quot;Count \t= &quot; + GetAllPrimesLessThan(maxprime).Count);
              richTextBox2.Text += Environment.NewLine + (&quot;Time \t= &quot; + stopwatch.Elapsed);
              richTextBox2.Text += Environment.NewLine + (&quot;--------------------------------&quot;);
              maxprime *= 10;
              richTextBox2.Refresh();
          }
          catch (Exception exception)
          {
              s = exception.Message + &quot;; Allocation size: &quot; + (maxprime + 1).ToString(&quot;N0&quot;);
              break;
          }
          
      }
      if (!string.IsNullOrEmpty(s))
      {
          richTextBox2.Text += Environment.NewLine + s;
      }
      richTextBox2.Text += Environment.NewLine + (&quot;Done.&quot;);
  }
  
  private static List&lt;ulong&gt; GetAllPrimesLessThan(ulong maxPrime)
  {
      var primes = new List&lt;ulong&gt;() { 2 };
      var maxSquareRoot = Math.Sqrt(maxPrime);
      var eliminated = new bool[maxPrime + 1];
  
      for (ulong i = 3; i &lt;= maxPrime; i += 2)
      {
          if (!eliminated[i])
          {
              primes.Add(i);
              if (i &lt; maxSquareRoot)
              {
                  for (ulong j = i * i; j &lt;= maxPrime; j += 2 * i)
                  {
                      eliminated[j] = true;
                  }
              }
          }
      }
      return primes;
  }
  </code></pre>
  <p>Which output this:</p>
  <pre><code>[...]
  Max     = 1 000 000 000
  Count   = 50847534
  Time    = 00:00:15.3355367
  --------------------------------
  Max     = 10 000 000 000
  Array dimensions exceeded supported range.; Allocation size: 10 000 000 001
  Done.
  </code></pre>
  <p>How can I get rid of this error?</p>
  <hr />
  <p>FYI: I've got</p>
  <ul>
  <li>16GB ram;</li>
  <li>32GB memory mapped(/paged?) on SSD;</li>
  <li>64bits enabled</li>
  </ul>