Note that there are some explanatory texts on larger screens.

plurals
  1. PO'System.OutOfMemoryException' was thrown when there is still plenty of memory free
    text
    copied!<p>This is my code:</p> <pre><code>int size = 100000000; double sizeInMegabytes = (size * 8.0) / 1024.0 / 1024.0; //762 mb double[] randomNumbers = new double[size]; </code></pre> <p>Exception: Exception of type 'System.OutOfMemoryException' was thrown.</p> <p><strong>I have 4GB memory on this machine 2.5GB is free</strong> when I start this running, there is clearly enough space on the PC to handle the 762mb of 100000000 random numbers. I need to store as many random numbers as possible given available memory. When I go to production there will be 12GB on the box and I want to make use of it.</p> <p><strong>Does the CLR constrain me to a default max memory to start with? and how do I request more?</strong></p> <p><strong>Update</strong></p> <p>I thought breaking this into smaller chunks and incrementally adding to my memory requirements would help if the issue is due to <strong>memory fragmentation</strong>, but it doesn't <strong>I can't get past a total ArrayList size of 256mb regardless of what I do tweaking blockSize</strong>.</p> <pre><code>private static IRandomGenerator rnd = new MersenneTwister(); private static IDistribution dist = new DiscreteNormalDistribution(1048576); private static List&lt;double&gt; ndRandomNumbers = new List&lt;double&gt;(); private static void AddNDRandomNumbers(int numberOfRandomNumbers) { for (int i = 0; i &lt; numberOfRandomNumbers; i++) { ndRandomNumbers.Add(dist.ICDF(rnd.nextUniform())); } } </code></pre> <p>From my main method:</p> <pre><code>int blockSize = 1000000; while (true) { try { AddNDRandomNumbers(blockSize); } catch (System.OutOfMemoryException ex) { break; } } double arrayTotalSizeInMegabytes = (ndRandomNumbers.Count * 8.0) / 1024.0 / 1024.0; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload