I have a C++ graphics app that does heavy computations on models. There is a leak or two which I've traced to CG and/or my ATI graphics card (I'm 100% SURE!!). The machine I have has 16 GB ram, and when I've used 4.49 GB RAM (TOTAL system usage, with app only using ~1.9GB), vector.resize() starts returning 0 new elements and not being able to resize an array. Why so soon?
Asked
Active
Viewed 99 times
3 Answers
3
(Windows Assumed)
A 32-bit Windows application is limited to about 2.0 GB of user-mode memory (or 3.0 GB if certain boot-time parameters are set). When your application used up 1.9 GB of memory, the well ran dry.
Reference: http://msdn.microsoft.com/en-us/library/windows/desktop/aa366778(v=vs.85).aspx#memory_limits

John Dibling
- 99,718
- 31
- 186
- 324
-
Ok! In VS 2010 [Project Properties/Config/Linker/System: Enable Large Addresses=YES](http://msdn.microsoft.com/en-us/library/wz223b1z(VS.80).aspx) – bobobobo Sep 19 '11 at 15:32
-
That's only half of it. You also have to have Windows boot in such a way so that 3GB is reserved for user space, rather than the usual 2 GB. The method for doing this differs with your specific version of Windows. – John Dibling Sep 19 '11 at 15:54
-
See here: http://msdn.microsoft.com/en-us/library/windows/desktop/bb613473(v=vs.85).aspx – John Dibling Sep 19 '11 at 15:55
-
And here: http://blogs.technet.com/b/brad_rutkowski/archive/2006/10/03/hey-where-did-_2f00_3gb-go-in-longhorn-and-vista_3f00_.aspx – John Dibling Sep 19 '11 at 15:55
-
INTERESTING. That's why I saw [this](http://i.imgur.com/LdMsJ.png) on first launch+crash (and after it changed "compatibility settings", it ran successfully (and is consuming 5.5GB as we speak!)) – bobobobo Sep 19 '11 at 23:29
1
I changed the build configuration to x64 and the application works fine

bobobobo
- 64,917
- 62
- 258
- 363
0
Throw an exception! Best to find and stamp on the leak, of course, but when you run out of memory: exception! To be extra cool restart your own application in response.

noelicus
- 14,468
- 3
- 92
- 111
-
This requires wrapping EVERY `.resize()` with a check that `.size()`== size_you_wanted, and every `malloc()` and `new` must be checked to see if NULL was returned. – bobobobo Sep 19 '11 at 15:24