c# out of memory question

P

pberent

I am trying to run a c# program which loads very large arrays (total
of about 1.2GB). I have 2GB of RAM on my machine and looking at task
manager it doesnt look like it has all been used. I have set virtual
memory (ie disk space to be used as RAM) to 3070MB. I have tested my
RAM using a RAM testing utility and it seems fine. I am getting an out
of memory error.

I started by using visual c# 2002 but someone told me that it was
buggy so I swithced to visual c# express...but no help. I cut the
program down to a very simple test version...which follows. Are ther
any setting I can change on my PC or within c# to get this to work?

here is the code:
using System;

namespace test1
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class testmain
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
try {
testclass testclass1 = new testclass();
}
catch {
int yyy=4;
}
}
}
class testclass {

double [] frogarray;
double [] frogarray1;

public testclass() {
frogarray = new double[150100000];
frogarray1 = new double[50000];
int aaa=3;
}
}
}
 
M

Michael A. Covington

I have reproduced the error using Visual Studio 2005. The largest array I
can allocate is about 110,000,000 of double (= 880,000,000 bytes). I can't
get 120,000,000 (= 960,000,000 bytes).

It seems reasonable to suppose that, in 32-bit Windows, the memory used by a
running application is limited to 1 GB, and part of that is of course your
program and the .NET Framework.

Here's some discussion:
http://www.dotnet247.com/247reference/msgs/55/276803.aspx

Apparently we've found the Achilles' heel of .NET Framework. For a
workaround, see the remarks about editbin and LARGEADDRESSAWARE near the
bottom.
 
P

pberent

Hey Michael
Thanks so much for your help on that...it seems like the first real
progress Ive made on this in DAYS!!
One more thing ...it says that I need to enter the linker option
through the property pages tab. Unfortunately, this is greyed out..and
does nothing when I click it...any ideas on this one?
I have reproduced the error using Visual Studio 2005. The largest array I
can allocate is about 110,000,000 of double (= 880,000,000 bytes). I can't
get 120,000,000 (= 960,000,000 bytes).

It seems reasonable to suppose that, in 32-bit Windows, the memory used by a
running application is limited to 1 GB, and part of that is of course your
program and the .NET Framework.

Here's some discussion:
http://www.dotnet247.com/247reference/msgs/55/276803.aspx

Apparently we've found the Achilles' heel of .NET Framework. For a
workaround, see the remarks about editbin and LARGEADDRESSAWARE near the
bottom.


I am trying to run a c# program which loads very large arrays (total
of about 1.2GB). I have 2GB of RAM on my machine and looking at task
manager it doesnt look like it has all been used. I have set virtual
memory (ie disk space to be used as RAM) to 3070MB. I have tested my
RAM using a RAM testing utility and it seems fine. I am getting an out
of memory error.

I started by using visual c# 2002 but someone told me that it was
buggy so I swithced to visual c# express...but no help. I cut the
program down to a very simple test version...which follows. Are ther
any setting I can change on my PC or within c# to get this to work?

here is the code:
using System;

namespace test1
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class testmain
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
try {
testclass testclass1 = new testclass();
}
catch {
int yyy=4;
}
}
}
class testclass {

double [] frogarray;
double [] frogarray1;

public testclass() {
frogarray = new double[150100000];
frogarray1 = new double[50000];
int aaa=3;
}
}
}
 
J

Jigar Mehta

Hello (e-mail address removed),

I think you can set the linker option alternatively using EditBin utility
as mentioned there.

Read more about it here,
http://msdn2.microsoft.com/en-us/library/xd3shwhf.aspx

Share your results then,

Jigar Mehta
http://jigar-mehta.blogspot.com
Hey Michael
Thanks so much for your help on that...it seems like the first real
progress Ive made on this in DAYS!!
One more thing ...it says that I need to enter the linker option
through the property pages tab. Unfortunately, this is greyed out..and
does nothing when I click it...any ideas on this one?
Michael said:
I have reproduced the error using Visual Studio 2005. The largest
array I can allocate is about 110,000,000 of double (= 880,000,000
bytes). I can't get 120,000,000 (= 960,000,000 bytes).

It seems reasonable to suppose that, in 32-bit Windows, the memory
used by a running application is limited to 1 GB, and part of that is
of course your program and the .NET Framework.

Here's some discussion:
http://www.dotnet247.com/247reference/msgs/55/276803.aspx
Apparently we've found the Achilles' heel of .NET Framework. For a
workaround, see the remarks about editbin and LARGEADDRESSAWARE near
the bottom.

I am trying to run a c# program which loads very large arrays (total
of about 1.2GB). I have 2GB of RAM on my machine and looking at task
manager it doesnt look like it has all been used. I have set virtual
memory (ie disk space to be used as RAM) to 3070MB. I have tested my
RAM using a RAM testing utility and it seems fine. I am getting an
out of memory error.

I started by using visual c# 2002 but someone told me that it was
buggy so I swithced to visual c# express...but no help. I cut the
program down to a very simple test version...which follows. Are ther
any setting I can change on my PC or within c# to get this to work?

here is the code:
using System;
namespace test1
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class testmain
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
try {
testclass testclass1 = new testclass();
}
catch {
int yyy=4;
}
}
}
class testclass {
double [] frogarray;
double [] frogarray1;
public testclass() {
frogarray = new double[150100000];
frogarray1 = new double[50000];
int aaa=3;
}
}
}
 
W

Willy Denoyette [MVP]

|I am trying to run a c# program which loads very large arrays (total
| of about 1.2GB). I have 2GB of RAM on my machine and looking at task
| manager it doesnt look like it has all been used. I have set virtual
| memory (ie disk space to be used as RAM) to 3070MB. I have tested my
| RAM using a RAM testing utility and it seems fine. I am getting an out
| of memory error.
|
| I started by using visual c# 2002 but someone told me that it was
| buggy so I swithced to visual c# express...but no help. I cut the
| program down to a very simple test version...which follows. Are ther
| any setting I can change on my PC or within c# to get this to work?
|
| here is the code:
| using System;
|
| namespace test1
| {
| /// <summary>
| /// Summary description for Class1.
| /// </summary>
| class testmain
| {
| /// <summary>
| /// The main entry point for the application.
| /// </summary>
| [STAThread]
| static void Main(string[] args)
| {
| try {
| testclass testclass1 = new testclass();
| }
| catch {
| int yyy=4;
| }
| }
| }
| class testclass {
|
| double [] frogarray;
| double [] frogarray1;
|
| public testclass() {
| frogarray = new double[150100000];
| frogarray1 = new double[50000];
| int aaa=3;
| }
| }
| }
|

Each process on Windows can allocate 2GB of Virtual Address Space (VAS),
however, this memory range is also used to load your code modules, the CLR
run-time modules, the native Win32 process heaps, thread stacks etc.
Loading of these modules (DLL's) at process creation time, results in a
fragmented VAS, such that only a part of the 2GB VAS is free for data
allocations (such as the GC heap).
A small console application (as you posted), NOT running in VS or in a
debugger, should have at least 1.6 GB of *contigious* memory available [1],
this means that this *exact* code should run. Note that all depends on the
OS and the version of the CLR and the type of program, here I'm talking
about XP SP2 and the v2 CLR and the program you posted, other OS versions
may load the modules at different addresses and other type of appications
may load more modules (think Windows.Forms).
Applying the 3GB switch and patching the exe (using editbin) such that it
becomes /LARGEADDRESSAWARE isn't of great help, all you get is an extra 1GB
of memory, but this one is separated from the other free block of memory in
the process, so, the largest contigious block of memory stays the same.
Note that you should never assume you will have that huge (say > 1GB) amount
of *contigious* memory available on 32 bit a OS, if this is what you are
after you should move to a 64 bit OS.


Willy.

[1]
This should work when running from the commandline, on XP with V2 of the
framework.

frogarray = new double[200000000]; // ~1.600.000 Bytes
frogarray1 = new double[500000]; // another ~400.000.000 Bytes
 

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