Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Short answer</strong> - dev server is 32bit process.</p> <p>Long answer for "why just 256Mb?"</p> <p>First of all, let's understand how it works.</p> <p>MemoryStream has internal byte[] buffer to keep all the data. It cannot predict exact size of this buffer, so it just initializes it with some initial value. </p> <p>Position and Length properties don't reflect actual buffer size - they are logical values to reflect how many bytes is written, and easily may be smaller than actual physical buffer size.</p> <p>When this internal buffer can not fit all the data, it should be "re-sized", but in real life it means <strong>creating new buffer</strong> twice as size as previous one, and then copying data from old buffer to new buffer.</p> <p>So, if the length of your buffer is 256Mb, and you need new data to be written, this means that .Net need to find yet another 512Mb block of data - having all the rest in place, so heap should be at least 768Mb on the moment of memory allocation when you receive OutOfMemory.</p> <p>Also please notice that by default no single object, including arrays, in .Net can take more than 2Gb in size.</p> <p>Ok, so here is the sample piece which simulates what's happening:</p> <pre><code> byte[] buf = new byte[32768 - 10]; for (; ; ) { long newSize = (long)buf.Length * 2; Console.WriteLine(newSize); if (newSize &gt; int.MaxValue) { Console.WriteLine("Now we reach the max 2Gb per single object, stopping"); break; } var newbuf = new byte[newSize]; Array.Copy(buf, newbuf, buf.Length); buf = newbuf; } </code></pre> <p>If it built in x64/AnyCPU and runs from console - everything is ok. </p> <p>If it built across x86 - it fails in console. </p> <p>If you put it to say Page_Load, built in x64, and open from VS.Net web server - it fails.</p> <p>If you do the same with IIS - everything is ok.</p> <p>Hope this helps.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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