This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Add configure flag for operator new (std::nothrow)
- From: Daniel Gutson <daniel dot gutson at tallertechnologies dot com>
- To: Jonathan Wakely <jwakely dot gcc at gmail 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>, daniel dot gutston at tallertechnologies dot com
- Date: Thu, 5 Nov 2015 12:22:38 -0300
- 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 Wed, Nov 4, 2015 at 3:20 AM, Jonathan Wakely <jwakely.gcc@gmail.com> 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).
>
>> In fact, our idea is that since the nothrow new can indeed return nullptr,
>> let the new_handler do something else and leave the no-memory-consequence
>> to the caller.
>> This new flag enables just that.
>
>
> The default configuration already allows the caller to deal with
> allocation failure from the nothrow version of new, by not installing
> a new-handler installed, and dealing with a null return value. How
> would I use this alternative configuration? Since the behaviour only
> changes when a new-handler is installed, presumably I'm meant to
> install some kind of new-handler that does something else ... but
> what? The patch should include documentation explaining when and how
> to use this option.
Real use cases: statistics and logging. It's a (one time) callback
reporting that something went wrong,
but not intended to fix things e.g. by attempting to free more memory.
--
Daniel F. Gutson
Chief Engineering Officer, SPD
San Lorenzo 47, 3rd Floor, Office 5
CÃrdoba, Argentina
Phone: +54 351 4217888 / +54 351 4218211
Skype: dgutson
LinkedIn: http://ar.linkedin.com/in/danielgutson