I have a situation in which malloc()returns NULLand sets errnoto ENOMEM. But the CRT heap (which is growing) has a lot of memory to work with. During mallocmy process memory is about 900 MB. A host process is a Java executable that runs under the Sun HotSpot JVM.
malloc()I am doing 80 megabytes and failing. If I make a allocation of 60 MB, it will be successful. After that, 50 MB is allocated, and then another, and one more: it is obvious that I have a lot of memory left, but the 80 MB malloc seems too "big" to digest the OS.
I am using Windows 7 x64 SP1 with 4 GB of RAM. My process is a 32-bit process built with VC ++ 2010 SP1. I use the Low Fragmentation Heap, which is the default value for Win 7. I also checked using HeapQueryInformation. The VC2010 C Run-Time that I use creates a bunch like this:
HeapCreate(0, BYTES_PER_PAGE, 0)
According to the documentation HeapCreate, it HeapAllocwill automatically call VirtualAllocfor blocks larger than 512 KB.
What the hell could cause an error malloc()if it is not a lack of memory? Is my memory too fragmented? I thought that Windows would automatically compress the heap. This is really strange, I've never seen this before.
Another computer with a 32-bit version of Windows XP SP3 has the same behavior.
Thanks Martin