c++ 内存的例子

xiaoxiao2021-02-28  89

// 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

转载请注明原文地址: https://www.6miu.com/read-72580.html

最新回复(0)