1 million integer problem..

I intend to study different sorting algorithms on large arrays..
I am trying to use 1 million array in C++
It gives me stack overflow..

Why? and how to solve it...?
1 million integers on windows == 4 million bytes.

Use a std::deque.
It worked after declaring the integer array outside the main as globals...


Last edited on
Firstly, globals are bad, bad, bad. Secondly, you need to alocate that memory on the heap and not on the stack. Stacks tend to be about 16 kiB AFAIK; so you can't push 4 million bytes onto it.

I don't see why declaring the array as a global should help you. It doesn't make any sense.
Globals are static data, and static data is not pushed onto the stack.
Oh, so like strings, then? They go in the .bss section and get mapped elsewhere in memory?
Topic archived. No new replies allowed.