This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: [PATCH] Add configure flag for operator new (std::nothrow)
- From: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- To: Daniel Gutson <daniel dot gutson at tallertechnologies dot com>
- Cc: Martin Sebor <msebor at gmail dot com>, Aurelio Remonda <aurelio dot remonda at tallertechnologies dot com>, "libstdc++" <libstdc++ at gcc dot gnu dot org>, "gcc-patches at gcc dot gnu dot org" <gcc-patches at gcc dot gnu dot org>
- Date: Wed, 4 Nov 2015 12:02:27 +0530
- Subject: Re: [PATCH] Add configure flag for operator new (std::nothrow)
- Authentication-results: sourceware.org; auth=none
- References: <1446554133-3090-1-git-send-email-aurelio dot remonda at tallertechnologies dot com> <56391843 dot 1070807 at gmail dot com> <CAF5HaEVeD4G1Mj8GwbpLyZ8V+GWNRAy1=5qbfVHgrZ=GpkbHbg at mail dot gmail dot com> <CAH6eHdQ_8cL8rqsX5u3NrNouf6E2_LtRPQ5F-V-rgTQ3FZTRug at mail dot gmail dot com>
On 4 November 2015 at 11:50, Jonathan Wakely wrote:
> On 4 November 2015 at 02:11, Daniel Gutson wrote:
>> Since this is a nothrow new, we thought that probably the system
>> might not be exceptions-friendly (such as certain embedded systems),
>> so we wanted to provide the new_handler the ability to do something else
>> other than trying to allocate memory and keep the function iterating.
>
> That could be done using an alternative overload of operator new
> instead of altering the semantics of the standard one (that could be
> provided as a GNU extension, for example).
Another option would be to provide a new-handler that enables the
desired behaviour e.g.
void __no_retry_new_handler() { __throw_bad_alloc(); }
...
while (__builtin_expect ((p = malloc (sz)) == 0, false))
{
new_handler handler = std::get_new_handler ();
if (! handler || handler == __no_retry_new_handler)
return 0;
The caller would then be responsible for attempting to make more
memory available (rather than the new-handler doing it).