Why am I getting “Invalid Allocation Size: 4294967295 Bytes” instead of an std::bad_alloc exception?

前端 未结 3 490
广开言路
广开言路 2021-01-13 18:04

I wrote the following piece of code to allocate memory for an array:

try {
    int n = 0;
    cin >> n;
    double *temp = new double[n];
    ...
}
cat         


        
3条回答
  •  灰色年华
    2021-01-13 18:35

    If you are using Visual Studio for building, you may want to enable "large memory allocation" in Linker settings.

    Go to project Properties -> Linker -> System -> Enable Large Addresses set to "Yes (/LARGEADDRESSAWARE)"

提交回复
热议问题