I develop a Win32 application in Visual Studio 2008 (C++). It runs fine in either 32-bit or 64-bit Windows 7. However, sometimes I need to allocate quite big memory buffers (the application deals with lots of data), and if I do it in Windows 7 64-bit, it fails, in 32-bit it runs fine. By big memory buffers I mean one ~250MB and another ~150MB. I have 8GB RAM installed in my PC, and according to my information, the 64-bit OS makes 4GB availabla for a 32-bit application. I need nowhere near that limit, still malloc fails.
Any ideas why and what can I do about it?
Thanks in advance.
I develop a Win32 application in Visual Studio 2008 (C++). It runs fine in
Share
150MB and 250MB are not especially huge allocations. As others have noted, the problem you are hitting is most likely address space fragmentation (i.e. there is enough free space, it’s just not all in one piece).
In addition to the other suggestions:
MEM_RESERVEflag to reserve the address space and commit it later.