3 ms·
> Even in c++ could you not just define some int [1000][1000]foo? If it fits on the stack, yes. Typical code using MD-arrays is scientific code, and the data
by shakow 4mo ago
> Even in c++ could you not just define some int [1000][1000]foo?
If it fits on the stack, yes.
Typical code using MD-arrays is scientific code, and the data they manipulate generally do not fit there.
- j_w 4mo agoWould the compiler not allocate the memory contiguously on the heap in that case then? Seems like a reasonable thing to do.
- shakow 4mo agoNope. The C++ memory models is designed around no hidden/non-deterministic memory allocation. If you try to allocate 10MB on the stack, that's the dev problem if the program fails, it's not the compiler job to guesstimate whether something will fit there or not (and it's impossible anyway, the compiler can't know all the stack sizes a program will ever run on).