Re: c# out of memory question
- From: "Willy Denoyette [MVP]" <willy.denoyette@xxxxxxxxxx>
- Date: Sat, 25 Nov 2006 19:21:21 +0100
<pberent@xxxxxxxxx> wrote in message
news:1164471409.799317.32490@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|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
.
- References:
- c# out of memory question
- From: pberent
- c# out of memory question
- Prev by Date: Re: c# out of memory question
- Next by Date: Re: Application value null
- Previous by thread: Re: c# out of memory question
- Next by thread: Suggestions for studying for Brainbench test
- Index(es):
Relevant Pages
|