views:

512

answers:

3

hi friends

i m using malloc to allocate memory and memory requirements are greater than 1GB. so program is crashing...

i want to ask whether this problem can be solved??If yes than how??

my RAM size is 3GB and using 32 bit windows os and programming using vc++

+2  A: 

On a 32 bit windows OS , each process gets 4 GB virtual address space out of which 2 GB is available for user and 2 GB is for Kernel. So whatever allocations done should be within this 2 GB space. Note that this 2 GB contains other things such as the other dlls which are loaded by your application, so this memory is fragmented. When you do malloc(), since malloc guarantees that it returns a continuos block of memory the CRT will try to find 1 GB of continuos free memory which may not be avaiable, hence the malloc() fails. One way of solving this would be to use the memory mapped files and map only a portion of the required memory into your virtual address space.

Naveen
+4  A: 
Ben
+1  A: 

If there isn't enough continuos space in the virtual memory space it is not possible to real map memory block to it to be used. So you should check your memory areas.

Where do your dll and exes map to? There is a tool rebase.exe which is part of the ms vc framework which will allow you to realloc the position your dll or exe are loaded to. This could give you more free virtual memory space which will allow you to get greater memory blocks.

The profile option of the "dependency walker" will show you where your dlls and exe are loaded to.

vmmap from sysinternals could help to get a better understanding how mwmory is fragmented and handled.

Totonga