c++ 内存的例子
时间:2010-07-18 来源:daojin
// Win32MemoryTest.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <limits> #include <iostream> using namespace std; void noMoreMemory() { std::cerr<<"noMoreMemory"<<endl; } class X { int x; int y; int z; }; class Y { }; int _tmain(int argc, _TCHAR* argv[]) { set_new_handler(noMoreMemory); try { while(true) { X* p1 = new X[100000000]; } } catch(std::exception& bad) { cout<<bad.what()<<std::endl; exit(0); } return 0; }
可以看到,不断地进入了handle里面。也就是说,如果找不到内存,就不断地去调用handle
相关阅读 更多 +