This question is based on C / C++ memory allocation.
I read up on the differences between the stack and heap and one things confuses me. One should allocate memory in the heap for large objects, but one can also do so in the stack as a local variable.
From this thread (C/C++ maximum stack size of program) I understood that the stack is limited and the limits are relatively low (7.4MB maximum).
I tested this limit with the following program:
#include <vector>
int main() {
std::vector<double> test;
for (int i = 0; i < 5000000; i++){
test.push_back(i);
}
return 0;
}
The total allocated memory is 8 Byte * (5.000.000) = 40MByte. This does not seem to provoke any kind of error. I read on this resource (https://software.intel.com/en-us/articles/determining-root-cause-of-sigsegv-or-sigbus-errors), that a stack overflow might provoke a segmentation fault or bus error.
So I guess, the question is: What happens when you "allocate" more memory in the stack than you can?