Reputation: 237
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.
Upvotes: 2
Views: 1673
Reputation: 1
I think there is a bug in malloc under win7-64. I have run the same tests with my 32-bit app on three machines: XP32, w7-32 and win7-64. It runs OK on the 32bit platforms but fails to allocate a 110Mb block under w7-64. I have de-fragmented my drive and tried again from a clean reboot with the same result.
K
Upvotes: -1
Reputation: 16896
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_RESERVE
flag to reserve the address space and commit it later.Upvotes: 1
Reputation: 69632
You are hitting virtual address space limit in your Win32 binary. The limit might be 2 to 4 GB depending on OS and environment. Actualy limit is less due to allocation fragmentation.
Your choices are to:
Upvotes: 1