C ++ application crashes when its memory usage reaches 1.5 GB

We have a C ++ application running on a 32-bit Windows system. It crashes after using memory to 1.5 GB. What we are unable to understand is that it crashes with a limit of 1.5 GB, and not with a 2 GB limit (virtual address space and a limitation of the 32-bit Windows architecture)?

Other details: - Full memory available: 4 GB

Operating System: Windows XP

1.5 GB is the memory used only by this process.

Hi,

Sechin

+6
source share
3 answers

This is normal for 32-bit Windows.

If you don't have the / 3gb switch activated, you have a 2GB shared address space. However, minus the displayed executable file and at least half a dozen DLL and NLS files (for "hello world" - the real application is likely to be more like a dozen or two dozen of them).

Since they are not optimally located, you lose about half a gigabyte of addres space. The heap will not β€œenter” into this area, and therefore allocating more than 1.5 GB will fail.

Here is the address space of a "typical program":

enter image description here

Please note how very skillfully one DLL is located in approximately 1/3 of the address space, effectively "cutting off" a third of the used memory.

+9
source

Destruction of virtual memory can be the cause.

Another possible reason is how memory managers (memory pools) usually work. The memory manager is trying to reserve a memory block 2 times larger than the previous one. When the memory is already distributed quite a lot, this amount will be very large, and the memory allocation will not succeed, despite the fact that in fact there is still memory.

+4
source

You can enable dr. watson as the default debugger and see if you can unload the crash dump, then open the dump with visual studio or windbg and you will see the column before the crash, and then find out what is the real cause of the crash.

0
source

Source: https://habr.com/ru/post/886037/


All Articles