g++ (MinGW) compiles this code
int main() {
float test[520073];
}
without any errors, but when I run the executable it crashes. If I lower the number to 520072 it runs normally. When compiling with clang, the exe crashes even with a much shorter array (it crashes starting at a length somewhere between 200,000 and 300,000).
If I change float
to double
, the number above which it crashes gets about halved, which leads me to believe that the crash has something to do with too much memory being used. However I do not understand why the number is so drastically different between compilers, as sizeof(float)
returns 4
on both g++ and clang.
Also, 500,000 seems like a relatively low maximum array length. With float
s being 4 bytes in size, it would only take up 2Mb of memory.
What could cause this crash and is there any way I could make larger arrays without the program crashing?