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

2020-10-10 16:40:01 浏览数 (1)

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

代码语言:javascript复制
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;
}

0 人点赞