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