473,395 Members | 2,151 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Cross-compiler way to handle memory allocation failure ?

Hi!
What is the method you use to handle memory allocation failure in C++
using the "new" operator?
I used to only check if a NULL pointer is returned after the "new" call,
but that's probably only working in MSVC++.
I also read about the "bad_alloc" exception, but that doesn't seem to be
thrown by MSVC++.
Now, one could of course say "don't use MSVC++", but I'd rather like to
hear a good solution for being able to handle memory allocation failure
in a cross-compiler way (we're using MSVC++ on windows and gcc on
linux). Any ideas anyone?
Is installing a new handler the only way to be sure?
Koen
Jul 19 '05 #1
1 3346
"Koen" <no@ssppaamm.com> wrote in message news:<bd**********@gaudi2.UGent.be>...
Hi!
What is the method you use to handle memory allocation failure in C++
using the "new" operator?
I used to only check if a NULL pointer is returned after the "new" call,
but that's probably only working in MSVC++.
I also read about the "bad_alloc" exception, but that doesn't seem to be
thrown by MSVC++.
Not in the last two versions. You have to go back to the 6.0 series,
which predates the standard. Both VC7.0 and VC7.1 get it right.
Now, one could of course say "don't use MSVC++", but I'd rather like to
hear a good solution for being able to handle memory allocation failure
in a cross-compiler way (we're using MSVC++ on windows and gcc on
linux). Any ideas anyone?
Is installing a new handler the only way to be sure?


I believe installing a new handler is also buggy on VC6. Upgrading from
VC6 to VC7 is relatively painless; i've done it on more than one project.
As others mentioned, new(nothrow) is an option.

For windows, this often is a bit of a non-issue though. Windows will
swap to death before failing, the user will probably kill off the
program first. The only case I know that fails fast enough to matter is
running into the 2Gb limit, if your PC has more than 2Gb RAM. I don't
know if that's implemented properly in VC6, though.

Regards,
--
Michiel Salters
Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Web Science | last post by:
Site and Features: http://www.eigensearch.com Search engine, eigenMethod, eigenvector, mathematical, manifolds, science, technical, search tools, eigenmath, Jacobian, quantum, mechanics,...
12
by: * ProteanThread * | last post by:
but depends upon the clique: ...
3
by: rollasoc | last post by:
Hi, Doing a bit of system testing on a Windows 98 laptop. (.Net 1.1 app). Did a bit of testing. Loaded a previously saved file. A gray box appeared with the text and buttons all white...
0
by: Web Science | last post by:
Site and Features: http://www.eigensearch.com Search engine, eigenMethod, eigenvector, mathematical, manifolds, science, technical, search tools, eigenmath, Jacobian, quantum, mechanics,...
23
by: Jeff Rodriguez | last post by:
Here's what I want do: Have a main daemon which starts up several threads in a Boss-Queue structure. From those threads, I want them all to sit and watch a queue. Once an entry goes into the...
0
by: Web Science | last post by:
Site and Features: http://www.eigensearch.com Search engine, eigenMethod, eigenvector, mathematical, manifolds, science, technical, search tools, eigenmath, Jacobian, quantum, mechanics,...
1
by: Rob Woodworth | last post by:
Hi, I'm having serious problems getting my report to work. I need to generate a timesheet report which will contain info for one employee between certain dates (one week's worth of dates). I...
6
by: Simon | last post by:
Hi All, An experiment i'm doing requires requires a synchronous cross-domain request, without using a proxy. I wondered if anyone had any ideas to help me achieve this. Below is what I have...
6
by: Bart Van der Donck | last post by:
Hello, I'm presenting my new library 'AJAX Cross Domain' - a javascript extension that allows to perform cross-domain AJAX requests. http://www.ajax-cross-domain.com/ Any comments or...
6
by: ampo | last post by:
Hello. Can anyone help with cross-domain problem? I have HTML page from server1 that send xmlHTTPRequest to server2. How can I do it? Thanks.
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.