分配失败
分配失败,会抛出std::bad_alloc exception,并且返回的指针为0;在抛出异常之前,会调用这个函数new_handler。
typedef void (*new_handler)();
- 让更多内存
- 调用abort,exit
new_handler set_new_handler(new_handler p) throw;
while(p==mallock(size)==0)
TRY_BEGIN
if(_callnewh(size))
Catch std::bad_alloc
Catch_END
范例
void noMoreMemory(){
cerr<<"out of memory";
abort();
}
void main()
{
set_new_handler(noMoreMemory);
}