set_new_handler
operator new がメモリを割り当てるとして失敗したときに呼び出されるユーザー関数をインストールします。
new_handler set_new_handler(
new_handler _Pnew
) throw( );
パラメーター
- _Pnew
インストールする new_handler。
戻り値
最初の呼び出しと 0 以降の呼び出しの前の new_handler。
解説
関数は維持する 新しいハンドラー の静的なポインターで _Pnew を貯えましたり、および以前に、ポインターに格納されている値を返します。新しいハンドラーは 新しい演算子size_t () で使用されます。
使用例
// 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;
}
}
必要条件
ヘッダー: <new>
名前空間: std