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).

Reply via email to