Topic: Q: new / new_handler / set_new_handler / C++ draft
Author: Dag Haugen <idb@vestnett.no>
Date: 1995/05/03 Raw View
kanze@lts.sel.alcatel.de (James Kanze US/ESC 60/3/141 #40763) wrote:
>
> In article <3o04ue$mg6@troll.vestnett.no> Dag Haugen <idb@vestnett.no>
> writes:
>
> [Valid critism of the new_handler deleted...]
>
> |> SUGGESTION:
> |> Define the following alternatives to new_handler/set_new_handler
> |> in the standard:
>
> |> typedef int (*new_recover)(size_t);
> |> new_recover set_new_recover(new_recover new_p);
>
> |> The default new implementation should call the new_recover when
> |> memory requests cannot be met and set_new_recover has been called.
> |> The function takes the requested size as argument, and if it
> |> returns non-zero, new should retry the allocation else return 0.
>
> Actually, my favorite variant is:
>
> typedef void* (*new_recover)( size_t ) ;
>
> "operator new" just returns whatever new_recover returns (supposing
> new_recover returns). With, of course, the qualification that
> new_recover could call operator new (for example, if it had made more
> memory available), and return the results of that call.
> --
Yes, I think this is better solution than my original suggestion
(which was identical to Microsoft's implementation of the new_handler)
Author: kanze@lts.sel.alcatel.de (James Kanze US/ESC 60/3/141 #40763)
Date: 1995/05/02 Raw View
In article <3o04ue$mg6@troll.vestnett.no> Dag Haugen <idb@vestnett.no>
writes:
[Valid critism of the new_handler deleted...]
|> SUGGESTION:
|> Define the following alternatives to new_handler/set_new_handler
|> in the standard:
|> typedef int (*new_recover)(size_t);
|> new_recover set_new_recover(new_recover new_p);
|> The default new implementation should call the new_recover when
|> memory requests cannot be met and set_new_recover has been called.
|> The function takes the requested size as argument, and if it
|> returns non-zero, new should retry the allocation else return 0.
Actually, my favorite variant is:
typedef void* (*new_recover)( size_t ) ;
"operator new" just returns whatever new_recover returns (supposing
new_recover returns). With, of course, the qualification that
new_recover could call operator new (for example, if it had made more
memory available), and return the results of that call.
--
James Kanze Tel.: (+33) 88 14 49 00 email: kanze@gabi-soft.fr
GABI Software, Sarl., 8 rue des Francs-Bourgeois, F-67000 Strasbourg, France
Conseils en informatique industrielle --
-- Beratung in industrieller Datenverarbeitung