I’m doing a build on Visual Studio in 64 bit mode, and get error
c2148 – total size of array must not exceed 0x7fffffff bytes,
but the actual threshold is 0xffffffff for std::new and doesn’t
appear to have a limit if using malloc instead.
I have largeaddressaware option set.
#include <iostream>
#include <malloc.h>
#define NEW 0
#if 1
// error c2148 - total size of array must not exceed 0x7fffffff bytes
#define LEN (4ull*1024ull*1024ull*1024ul) // 0x100000000
#else
// no compile error even with NEW
#define LEN (4ull*1024ull*1024ull*1024ull-1ull) // 0x0ffffffff
#endif
int main(void)
{
uint8_t *arr;
size_t i;
int usednew;
usednew = 1;
arr = NULL;
#if NEW
arr = new(std::nothrow) uint8_t [LEN];
#else
if(arr == NULL){
usednew = 0;
arr = (uint8_t *)malloc(LEN);
}
#endif
for (i = 0; i < LEN; i++)
arr[i] = (uint8_t)i;
for(i = 1; i < LEN; i++){
if(arr[i-1] > arr[i]){
std::cout << "error" << std::endl;
break;
}
}
if(usednew)
delete[] arr;
else
free(arr);
return(0);
}
2
This problem was fixed in an update for Visual Studio 2022. You either did not get the update or you are using an older version of Visual Studio.
1