I am writing a program in C++ which has a requirement that:
new operator should return a NULL if it is unable to allocate memory, instaed of throwing an exception and exiting.
How can i acieve this ??????
Why???
When you run out of memory,
new throws a bad_alloc exception. At that time there will be just enough memory to create the exception.
In the case of Windoows, 3 hours before bad_alloc is thrown a message appears:
Windows running low on resources....
2 hours before bad_alloc is thrown, an hourglass apprears briefly when you allocate memory.
1 hour before bad_alloc is thrown, the hourglass appears for 2 seconds
30 minutes before bad_alloc is thrown, the hourglass appears for 1 minute each time you allocate.
15 minutes before bad_alloc is thrown, you notice the disc access light blinking
5 minutes before bad_alloc is thrown, the hourglass is on for 10 minutes each time you allocate and your PC is vibrating across the floor dues to the disc accesses.
1 minute before bad_alloc is thrown, your hard drive crashes from over use.
For Windows, this means your bad_alloc will never be thrown. That means you have no chance to reach in and re-engineer memory management.