win7 64位 下,进程可申请的堆空间

大致测试了下,堆区大概可以申请 1G这样。捕获 new 的异常,一般抛出 std::bad_alloc

 

void test(){
    char * c = NULL;
    // input bad_alloc
    //unsigned int i = (unsigned int)pow(2,31);

    // ok
    unsigned int i = (unsigned int)pow(2,30);
    try{
        c = new char[i];
    }catch(bad_alloc& e){
        cout << e.what() << endl;
        //cout << s << endl;
    }
    if( c != NULL)
        delete []c;
}

 

posted @ 2015-09-07 14:25  forxtz  阅读(324)  评论(0)    收藏  举报