tags:

views:

120

answers:

4

I'm sure I saw this happening to me once. In a 64-bit OS with 8 GB of RAM, I would still get an Exception when an array will be ca. 2 GB. What's the exception name?

Please, don't tell me that my program is bad because I shouldn't be doing that. Believe me, it was required.

EDIT: The program was running as a 64-bit process.

+2  A: 

OutOfMemoryException perhaps? Just because your machine has 8GB of memory doesn't mean that your application has access to all of it.

Without knowing any more than what you have posted, I would assume that your application is running in a 32-bit process (even though you are on a 64-bit processor) and as such is limited to the 2GB virtual address space of that 32-bit process. This is all just speculation of course, there are many reasons why you could see an OutOfMemoryException and without more details it is impossible to say why.

Andrew Hare
Why OutOfMemoryException is a linked to mentalis's proxy project? Is the OOM exception described there?
Vadmyst
My mistake! That was a link I copied for another answer - thanks for catching that.
Andrew Hare
+1  A: 

You should just get a System.OutOfMemoryException

Look at this page for a discussion about it. (Sorry for the google cache result, the dotnet247.com site appears to be down at the time of this answer)

marcc
+4  A: 

The following throws OutOfMemoryException on my Windows Server 2008 64 bit with 8Gb RAM:

var a = new int[int.MaxValue];
zvolkov
+3  A: 

I checked (Vista Ultimate 64bit with 4GB physical memory), the code:

byte[] x = new byte[2147483648];

throws an OverflowException (because 2147483648 doesn't fit into a signed int)

byte[] x = new byte[2147483647];

throws an OutOfMemoryException

byte[] x = new byte[2147483591];

successfully allocates the array, that is the maximum size that works on my machine.

according to this post http://blogs.msdn.com/joshwil/archive/2005/08/10/450202.aspx it's was a design choice to artificially limit managed object size to 2GB.

You can allocate unmanaged memory using P/Invoke and access it with unsafe code and pointers if you must.

Nir