views:

72

answers:

1

Hello everybody.

I am using visual studio 2008 for developing. My program needs to deal with a huge amount of memory. The error happens when my program try to allocate a 512M float array. Code is the following:

int size = 512*512*512;
float *buffer = new float[size];

Before this allocation, the program already consumed around 554M memory. My desktop has 4G main memory and I am using windows xp 32bits.

How can I avoid the allocation error? Thanks very much for your input!

+3  A: 

Your array requires too much contiguous memory. Your program has a bit less of 2 gigabytes of virtual memory available but that address space is broken up by chunks of code, data and various heaps. Memory is allocated from the free space between those chunks. On a 32-bit operating system you can get ~650 MB when you allocate immediately. That goes South when your program starts using memory. The sum of all memory allocations is still ~2GB.

Use a 64-bit operating system or partition your data structures. SysInternals' VMMap utility can give you insight in the virtual memory mapping of your program.

Hans Passant
Using the /LARGEADDRESSAWARE linker switch can get you past the 2GB limit. I think you're fine up to around 3GB. Of course, your point about contiguous memory still holds.
Nathan Ernst
Meh, getting the boot option to work is the rub.
Hans Passant
the software you recommend is pretty good. Thanks.
Aaron