set_new_handler
Installa una funzione utente che deve essere chiamata quando operator new non riesce nel tentativo di allocare memoria.
new_handler set_new_handler(
new_handler _Pnew
) throw( );
Parametri
- _Pnew
Il new_handler da installare.
Valore restituito
0 la prima chiamata e new_handler precedente alle chiamate successive.
Note
La funzione contiene _Pnew in un puntatore statico nuovo gestore che gestisce, quindi restituisce il valore precedentemente memorizzato nel puntatore.Il nuovo gestore viene utilizzato da operatore new(size_t).
Esempio
// new_set_new_handler.cpp
// compile with: /EHsc
#include<new>
#include<iostream>
using namespace std;
void __cdecl newhandler( )
{
cout << "The new_handler is called:" << endl;
throw bad_alloc( );
return;
}
int main( )
{
set_new_handler (newhandler);
try
{
while ( 1 )
{
new int[5000000];
cout << "Allocating 5000000 ints." << endl;
}
}
catch ( exception e )
{
cout << e.what( ) << endl;
}
}
Requisiti
intestazione: <new>
Spazio dei nomi: deviazione standard