views:

112

answers:

4

I have an application that allocates memory with 'new' and frees them with 'delete' in some parts of the code. The problem is that whenever it exceeds the memory limit of the system (let's say 2GB), Windows sends a Kill signal to the process. I think it is not usual since it should use the swap space(I think in windows it is called virtual memory), right? My application is written in C++/Visual Studio.

+1  A: 

Windows doesn't use signals. You should get the std::badalloc exception when you run out of memory. Which, when uncaught, will automatically run the terminate() function. The exception is visible in the Output window.

Hans Passant
+2  A: 

Here is how you can make it up to 3GB for a process; That is the absolute max you can have it for 32 bit windows apps. Any more than that and you are going to need to use a 64 bit version of windows.

That is a lot of memory. maybe you could consider splitting your app into multiple processes and communicating between them.

Romain Hippeau
A: 

I haven't looked too closely at this, but you may find the answers you want here:

http://stackoverflow.com/questions/181050/can-you-allocate-a-very-large-single-chunk-of-memory-4gb-in-c-or-c

Mike Caron
+2  A: 

The OS doesn't kill your app, an unhandled exception does. You will want to examine your app with perfmon, and watch these counters, Working Set, Virtual Bytes, Private Bytes. You will get exceptions when your reserved bytes gets close to 2GB. So your committed bytes and RAM bytes are much less.

Here is a nice article on Virtual Address Space, including committed vs reserved.

The moral of the story, don't try to allocate when the reserved bytes gets close to 2GB, for a 32-bit process.

Chris O