CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Karl Seguin

.NET From Ottawa, Ontario - http://twitter.com/karlseguin/

Funny - Newsgroup post about OutOfMemoryException

This just got posted to the ASP.NET newsgroup:

I'm getting an OutOfMemoryException when I initialize a byte array in
C# like this:

Byte[] test = new Byte[420000000];

 

Atleast he/she figured out what line was the likely culprit.



Comments

J said:

That's <i>only</i> 410 MB.

# September 26, 2006 12:50 PM

karl said:

I can see some slow for loops...

# September 26, 2006 1:15 PM

Ayende Rahien said:

I would assume that the computer he run it at had 512 MB or so.

Even 1Gb will often refuse to do this.

# September 26, 2006 1:25 PM

Simon said:

What an idiot!

# September 27, 2006 1:31 AM

Greg said:

just be glad it wasnt a stackalloc.

it is however quite common to initialize large byte arrays ... doing the above code once is not a big deal (allocating one time a 410mb chunk in the LOH is something I alot of (then I dish out arraysegment<byte> chunks of this larger array back to callers who need variable sized buffers .. if this were in an aspx page where it would be happenning often it is a very big deal ...

# September 27, 2006 10:27 AM

Leave a Comment

(required)  
(optional)
(required)  

Enter the numbers above:
Add
Check out Devlicio.us!

Our Sponsors