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

前端 未结 3 489
广开言路
广开言路 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:29

    On a 32-bit system, your virtual memory address space cannot exceed 2^31-1 (4294967295) bytes.

    You are attempting to allocate 536000000*sizeof(double) bytes, which is obviously more than that.

提交回复
热议问题