We have a C++ application running on Windows 32 bit system. It crashes once the memory usage reaches 1.5 GB. What we are unable to understand is why it's crashing at 1.5 GB limit and not at 2 GB limit (the virtual address space and windows 32 bit architecture limit)?
Other details:- Total memory available : 4GB
Operating System : Windows XP
1.5 GB is the memory used by just this one process.
Regards,
Sachin
This is perfectly normal under 32bit Windows.
Unless you have the /3gb switch activated, you have a total address space of 2GB. However, that's minus the mapped executable and at least half a dozen DLL and NLS files (for "hello world" -- a real application would probably have more like a dozen or two dozen of them).
Since they are not optimally placed, you lose about half a gigabyte of addres space. The heap will not grow "into" that region, and thus allocating more than 1.5GB will fail.
Here is what the address space of a "typical program" looks like:
Note how very skillfully one DLL is placed at about 1/3 of the address space, effectively "cutting off" a third of the memory that you can use.
The fragmentation of the virtual memory could be a reason.
One more possible reason is how memory managers (memory pools) are usually work. Memory manager attempts to reserve a block of memory 2 times more than the previous one. When memory is allocated already quite a lot, this amount will be very large and a memory allocation will fail despite the fact that in reality there is still available memory.
You can enable dr. watson as default debugger and see if a crash dump could be catched, then open the dump with visual studio or windbg and you can see the callstack before crash, and then know what is the real cause of the crash.
精彩评论