views:

51

answers:

1

After reading Are C# Strings (and other .NET API’s) limited to 2GB in size? I played around with large strings and arrays in .NET 3.5. I found that the largest array I could allocate was int.MaxValue - 56 bytes. Similar thing for strings: the largest I could get was (int.MaxValue - 58) / 2 characters (since each character took 2 bytes). After that it throws OutOfMemoryException.

Why does this limitation exist? Not that I've ever run into it in practice - I'm just curious about the inner workings of .NET.

Yes, this was on a 64-bit machine with plenty of RAM, of course - and yes, the process was running as a 64-bit process. (I could actually allocate 3 such arrays or strings for a total memory usage of 6GB.)

+1  A: 

It was a design decition to restrict the size of an object on the GC Heap to 2GB, even on x64. Good blog post on it here from one of those involved in the design decision:

http://blogs.msdn.com/b/joshwil/archive/2005/08/10/450202.aspx

David M
Thanks. That confirms that it was a conscious design decision, though it doesn't really explain why they made that decision.
Evgeny