In example 1 array is allocated on stack, in example 2 - on global memory
http://stackoverflow.com/questions/408670/stack-static-and-heap-in-c My opinion:
- stack is small;
- stack size is unpredictable.
Conclusion: there shouldn't be big variables on stack. There shouldn't be recursion with more than logarithm complexity. If recursion depth is above 100 then it isn't usable for practical purpose.
Note: STL containers aren't big despite dozens of elements inside.
They use heap to hold elements and don't spend too much stack size.
So here is ok:
int main() {
std::vector<double> array(128*1024);
...