2

I would like to use a large array on the stack. However I keep on getting stack overflow although I changed the stack reserve size. For example:

int main()
{
    int a[5000000];
    return 0;
}

and in visual studio 2012: Properties -> Linker -> System -> Stack reserve size: 10000000

What could cause it?

1 Answer 1

5

The size of an int is probably 4 bytes, so the array is larger in bytes than in the number of elements. sizeof(int)*5000000 is what you need. (at least)

Sign up to request clarification or add additional context in comments.

1 Comment

Yeah, that's the reason... This is weird because I tried previously to do this and I noticed that adding 1 to the stack reserve size lets me define one more int (= size of DWORD on my computer): I put in the stack reserve size 0 and it let me do an array of ints of size 62200, and when I put there 1 it let me define an array of size 62201..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.