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.
-
2AFAIK, a 32-bit process can not use more than 2GB in Windows. – ZippyV Aug 10 '10 at 17:43
-
1Use a 64bit version of windows and build your program as a 64bit target if you need more than 2GB. That's the limit for a 32bit application. – user328543 Aug 10 '10 at 18:00
-
I am not using 2GB of RAM in my process. About 1GB is already used by Windows. I am using around 1GB... but in total it exceeds the memory. So 32-bit issue is not the case. – Nima Aug 10 '10 at 18:06
-
Assuming your pagefile is large enough, in theory your process can allocate up to 2GB, irregardless of how much RAM is installed or is available. – Chris O Aug 10 '10 at 18:11
-
DUDES! I am using 1GB of RAM! – Nima Aug 10 '10 at 18:17
-
@Nima: How do you determine that? Where do you see how much memory is used by Windws, and how much by you? That information isn't straightforward, and you're most likely misunderstanding it. – jalf Aug 10 '10 at 18:28
-
1Also, what makes you think Windows isn't using its pagefile? (Virtual memory is *always* used, and isn't the same thing as swap space or pagefile) – jalf Aug 10 '10 at 18:34
-
I'm simply using task manager. before running the application, about 1GB is used by Windows, and after running the program, when it approaches 2GB, it crashes. This is my observation. Really? is it used all the times by windows? isn't it the same as swap space in linux? – Nima Aug 10 '10 at 20:25
4 Answers
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.

- 24,113
- 5
- 60
- 79
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.

- 5,017
- 3
- 35
- 42
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.

- 922,412
- 146
- 1,693
- 2,536
I haven't looked too closely at this, but you may find the answers you want here:
Can you allocate a very large single chunk of memory ( > 4GB ) in c or c++?

- 1
- 1

- 14,351
- 4
- 49
- 77