Windows XP Memory allocation questions
-
Hi, in the process of running my program is allocating a lot of memory (gigabytes). After it reaches a certain size strange things start to happen so I'm trying to debug it. I have some questions. 1. To my surprise new operator does not return NULL on error. It seems to throw an exception. When did this happen? What's the exception object? I'm using VS 8. 2. Is new a thread safe operator? What if I'm using some libraries that most likely use malloc. Is memory allocation still thread safe? I'm using dynamic link run time for my program and hopefully all the libraries. If some library is using a different run-time but I don't free its memory is that fine? 3. What is the memory allocation limit for a process in Windows XP? Is it 2 GB? Or RAM + swap space? 4. Any free GUI profilers out there? Thanks for your help.
-
Hi, in the process of running my program is allocating a lot of memory (gigabytes). After it reaches a certain size strange things start to happen so I'm trying to debug it. I have some questions. 1. To my surprise new operator does not return NULL on error. It seems to throw an exception. When did this happen? What's the exception object? I'm using VS 8. 2. Is new a thread safe operator? What if I'm using some libraries that most likely use malloc. Is memory allocation still thread safe? I'm using dynamic link run time for my program and hopefully all the libraries. If some library is using a different run-time but I don't free its memory is that fine? 3. What is the memory allocation limit for a process in Windows XP? Is it 2 GB? Or RAM + swap space? 4. Any free GUI profilers out there? Thanks for your help.
Budric B. wrote:
To my surprise new operator does not return NULL on error. It seems to throw an exception. When did this happen?
I thought it was a lot longer ago, but according to the docs: "In Visual C++ .NET 2002, the new function in the Standard C++ Library will support the behavior specified in the C++ standard, which is to throw a std::bad_alloc exception if the memory allocation fails.
In Visual C++ 2005, the C Runtime Library's new function will also throw a std::bad_alloc exception if the memory allocation fails.
If you still want the non-throwing version of new for the C Runtime Library, link your program with nothrownew.obj. However, when you link with nothrownew.obj, new in the Standard C++ Library will no longer function."
Budric B. wrote:
2. Is new a thread safe operator?
In the Multithread CRT, Yes. Any third-party library, well... Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
Hi, in the process of running my program is allocating a lot of memory (gigabytes). After it reaches a certain size strange things start to happen so I'm trying to debug it. I have some questions. 1. To my surprise new operator does not return NULL on error. It seems to throw an exception. When did this happen? What's the exception object? I'm using VS 8. 2. Is new a thread safe operator? What if I'm using some libraries that most likely use malloc. Is memory allocation still thread safe? I'm using dynamic link run time for my program and hopefully all the libraries. If some library is using a different run-time but I don't free its memory is that fine? 3. What is the memory allocation limit for a process in Windows XP? Is it 2 GB? Or RAM + swap space? 4. Any free GUI profilers out there? Thanks for your help.
Sounds to me like you have some serious memory leakage. Make sure you call delete on every time you allocate using new. Try this[^] utility, it's excellent for finding leaks. As for your questions: 1. use try catch blocks. 2. yes. 3. Usually RAM, but not too sure... 4. www.google.com
Waldermort
-
Hi, in the process of running my program is allocating a lot of memory (gigabytes). After it reaches a certain size strange things start to happen so I'm trying to debug it. I have some questions. 1. To my surprise new operator does not return NULL on error. It seems to throw an exception. When did this happen? What's the exception object? I'm using VS 8. 2. Is new a thread safe operator? What if I'm using some libraries that most likely use malloc. Is memory allocation still thread safe? I'm using dynamic link run time for my program and hopefully all the libraries. If some library is using a different run-time but I don't free its memory is that fine? 3. What is the memory allocation limit for a process in Windows XP? Is it 2 GB? Or RAM + swap space? 4. Any free GUI profilers out there? Thanks for your help.
Budric B. wrote:
1. To my surprise new operator does not return NULL on error. It seems to throw an exception. When did this happen? What's the exception object? I'm using VS 8.
That's the way it is supposed to work - it throws bad_alloc. If you want to get a NULL instead, use nothrow[^]
Budric B. wrote:
2. Is new a thread safe operator? What if I'm using some libraries that most likely use malloc. Is memory allocation still thread safe? I'm using dynamic link run time for my program and hopefully all the libraries. If some library is using a different run-time but I don't free its memory is that fine?
Yes. Yes. Yes.
Budric B. wrote:
3. What is the memory allocation limit for a process in Windows XP? Is it 2 GB? Or RAM + swap space?
In practice, less then 2GB[^] (BTW, who would vote down that text and why :confused: )
Budric B. wrote:
4. Any free GUI profilers out there?
Try GlowCode.
-
Budric B. wrote:
1. To my surprise new operator does not return NULL on error. It seems to throw an exception. When did this happen? What's the exception object? I'm using VS 8.
That's the way it is supposed to work - it throws bad_alloc. If you want to get a NULL instead, use nothrow[^]
Budric B. wrote:
2. Is new a thread safe operator? What if I'm using some libraries that most likely use malloc. Is memory allocation still thread safe? I'm using dynamic link run time for my program and hopefully all the libraries. If some library is using a different run-time but I don't free its memory is that fine?
Yes. Yes. Yes.
Budric B. wrote:
3. What is the memory allocation limit for a process in Windows XP? Is it 2 GB? Or RAM + swap space?
In practice, less then 2GB[^] (BTW, who would vote down that text and why :confused: )
Budric B. wrote:
4. Any free GUI profilers out there?
Try GlowCode.