16GB Limit for a single 1D array

16GB Limit for a single 1D array

My computer has 64-bit OS, 64-bit CPU and over 30GB RAM, but my code could not access more than 16GB. I am wondering if there is a 16GB limit for a single 1D array. Here is a simple test case.

__int64 i, n;
double *a=0;
n = 3000000000; // 3E+09
a = new double[n]; // allocate ~24GB.
for (i=0; i LT n; i++) a[i] = 1.0 * i;
delete[] a;

Are there any potential problems in this code segment?

Thank you. Jim

4 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

The line where you set n to -1294967296 is suspect.

I am not sure where you got n = -1294967296. Without using __int64, there is a clear limit of 16GB because the max value of an int = 2G. I set __int64 n = 3G on purpose here.

Xorpd tried to say that 3,000,000,000 = 0xB2D05E00. If passed as 32-bit int that is a -1294967296.

I suppose new allocates from heap. Perhaps there is a limit on heap size (the limit in CRT) for an application. Write replacement for a new and delete operators using VirtualAlloc and try again. If it allocates 24GB then it is a CRT (heap) limit, if not, then it is a compiler limit (it treats n as int).

Leave a Comment

Please sign in to add a comment. Not a member? Join today