Topic: set_new_handler functions returning


Author: berczuk@space.mit.edu (Steve Berczuk)
Date: 4 Aug 1993 18:55:07 GMT
Raw View
In article <spuler.743840151@coral>, spuler@coral.cs.jcu.edu.au (David Spuler) writes:
|> I have a question regarding the interaction between the 'new' operator
|> and the functions installed by 'set_new_handler'.
|> If the new operator fails, then calls a handler which does nothing and
|> simply returns, and the new operator continues to fail, does new repeatedly
|> call the handler (leading to an infinite loop)?

For a clearer example of how to use new_handler see Meyers: Effective C++ p 25.
The  example there calls new_handler only if there is a pointer to a new_handler.
If the first call to the new_handler fails, then a call is mail to
set_new_handler(0) thus avoiding an infinite loop. (perhaps this is what gcc does?)

BJS's example will avoid an infinite loop only if  exceptions are supported by the
compiler...

|>
|> I've implemented a version under g++ which seems to indicate that the
|> handler is called only once before new returns NULL.
|>
|> The ARM p218 seems unclear:  the top paragraph merely says that "new will
|> call [the handler] and make another attempt to allocate memory".
|> This would fit either the once-only or the repeated calls;
|> But the implementation example of new (also p281) uses repeated calls.
|> Stroustrup (2nd edn) also has a 'new' example on p312 using repeated calls.


--
Steve Berczuk   berczuk@mit.edu
MIT Center for Space Research (617) 253-3840





Author: spuler@coral.cs.jcu.edu.au (David Spuler)
Date: 28 Jul 93 06:15:51 GMT
Raw View
I have a question regarding the interaction between the 'new' operator
and the functions installed by 'set_new_handler'.
If the new operator fails, then calls a handler which does nothing and
simply returns, and the new operator continues to fail, does new repeatedly
call the handler (leading to an infinite loop)?

I've implemented a version under g++ which seems to indicate that the
handler is called only once before new returns NULL.

The ARM p218 seems unclear:  the top paragraph merely says that "new will
call [the handler] and make another attempt to allocate memory".
This would fit either the once-only or the repeated calls;
But the implementation example of new (also p281) uses repeated calls.
Stroustrup (2nd edn) also has a 'new' example on p312 using repeated calls.

Is the issue undefined in (future) ANSI C++?  Or is this just a g++ bug?

Thanks in advance,
David Spuler