OutOfMemoryException When Allocating Huge Objects That Use Lots ofRAM on 64-bit Machine

P

powwow

I am running out of memory (OutOfMemoryException) when I do something
like this:

Hashtable h = new Hashtable(10000000);

It doesn't seem to use all of the RAM on the machine. I have 4GB of
RAM installed.

I have a 64 bit OS (Windows Vista). I have 64 bit CPU. (Intel Quad
Core). So no 32-bit restriction argument applies here.

I am using Visual Express 2008 C#. Since it doesn't come with
editbin.exe I had to download Visual Express 2008 C++ and use it's
editbin.exe on my C# executable.

I executed "editbin /LARGEADDRESSAWARE program.exe" But when I run
program.exe it runs out of memory when I know there is RAM not being
used.

WHAT GIVES? PLEASE HELP. I feel like I bought a 64-bit machine for
nothing since the sole purpose was to allocate more memory than a 32-
bit OS.
 
W

Willy Denoyette [MVP]

powwow said:
I am running out of memory (OutOfMemoryException) when I do something
like this:

Hashtable h = new Hashtable(10000000);

It doesn't seem to use all of the RAM on the machine. I have 4GB of
RAM installed.

I have a 64 bit OS (Windows Vista). I have 64 bit CPU. (Intel Quad
Core). So no 32-bit restriction argument applies here.

I am using Visual Express 2008 C#. Since it doesn't come with
editbin.exe I had to download Visual Express 2008 C++ and use it's
editbin.exe on my C# executable.

I executed "editbin /LARGEADDRESSAWARE program.exe" But when I run
program.exe it runs out of memory when I know there is RAM not being
used.

WHAT GIVES? PLEASE HELP. I feel like I bought a 64-bit machine for
nothing since the sole purpose was to allocate more memory than a 32-
bit OS.



Are you sure about this?
(10000000);

This value should not be a problem, even on 32-bit it should be fine.
Please post a complete sample that illustrates the issue.


Willy.
 
P

powwow

Thanks for the reply. I have supplied the example below. When I run
with 60000000 it doesn't seem to use all the memory.

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Test
{
class Program
{
static void Main(string[] args)
{
Hashtable h = new Hashtable(70000000); //This will cause
System.OutOfMemoryException

//60000000 seems to work but not 70000000
}
}
}

Again, I am running 64-bit machine, 64 bit OS, Visual Express C# 2008
with 4GB RAM. I also use editbin /LARGEADDRESSAWARE on the exe.
Still there is an out of memory error.
 
D

Doug Forster

AFAIK individual objects are limited to 2GB even for the 64bit framework
(and yes this is a dumb restriction). I can only speculate that your
specified capacity causes this limit to be exceeded for some reason. The
LARGEADDRESSAWARE flag and the amount of RAM you have are irrelevant.

Cheers
Doug Forster

powwow said:
Thanks for the reply. I have supplied the example below. When I run
with 60000000 it doesn't seem to use all the memory.

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Test
{
class Program
{
static void Main(string[] args)
{
Hashtable h = new Hashtable(70000000); //This will cause
System.OutOfMemoryException

//60000000 seems to work but not 70000000
}
}
}

Again, I am running 64-bit machine, 64 bit OS, Visual Express C# 2008
with 4GB RAM. I also use editbin /LARGEADDRESSAWARE on the exe.
Still there is an out of memory error.


Are you sure about this?
(10000000);

This value should not be a problem, even on 32-bit it should be fine.
Please post a complete sample that illustrates the issue.

Willy.
 
W

Willy Denoyette [MVP]

Oh, but this is something different, 60000000 means an Hashtable of about
2.000.000.000 bytes of contagious memory, which is about the maximum size of
a single object on .NET (2GB).
Note that in your sample you don't insert any element in the table,when you
start adding elements to the table you will see the memory consumption grow
even above 4GB depending on the type and size of elements your are adding.
So while you can't create single objects that are larger than 2GB, you can
easily allocate a TB of data by using a container like a Hashtable.
Just try to add 60000000 elements (say an int string pair) to your table,
and watch your system grinding to halt, this because you are consuming more
than the available RAM memory, so that your system starts paging like mad.
Don't be surprised that the program never reached the end, the program will
fail if when all virtual memory (RAM + pagefile size) is consumed.
Some systems even crash when no more VM is left, you are warned ;-).


Willy.




powwow said:
Thanks for the reply. I have supplied the example below. When I run
with 60000000 it doesn't seem to use all the memory.

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Test
{
class Program
{
static void Main(string[] args)
{
Hashtable h = new Hashtable(70000000); //This will cause
System.OutOfMemoryException

//60000000 seems to work but not 70000000
}
}
}

Again, I am running 64-bit machine, 64 bit OS, Visual Express C# 2008
with 4GB RAM. I also use editbin /LARGEADDRESSAWARE on the exe.
Still there is an out of memory error.


Are you sure about this?
(10000000);

This value should not be a problem, even on 32-bit it should be fine.
Please post a complete sample that illustrates the issue.

Willy.
 
J

Jeroen Mostert

Willy said:
Oh, but this is something different, 60000000 means an Hashtable of
about 2.000.000.000 bytes of contagious memory, which is about the
maximum size of a single object on .NET (2GB).

Good thing, too, before that memory starts to infect the rest. :)

Do you have an autocorrecting spell-checker, by any chance? I could see it
making "contagious" out of anything that doesn't resemble "contiguous" enough.
 
W

Willy Denoyette [MVP]

Jeroen Mostert said:
Good thing, too, before that memory starts to infect the rest. :)

Do you have an autocorrecting spell-checker, by any chance? I could see it
making "contagious" out of anything that doesn't resemble "contiguous"
enough.

You (and I) don't want to see my auto-correcting spell-checker turned on
:), the result is some mix of Dutch , French and English.
I think it's just time to get some sleep that's all.


Willy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top