文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>c++ 内存的例子

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

相关阅读 更多 +
排行榜 更多 +
方块拼凑最新版 v1.0 安卓版

方块拼凑最新版 v1.0 安卓版

休闲益智 下载
方块拼凑最新版 v1.0 安卓版

方块拼凑最新版 v1.0 安卓版

休闲益智 下载
愤怒的小鸟爆破安卓版 v2.7.0 手机版

愤怒的小鸟爆破安卓版 v2.7.0 手机版

飞行射击 下载