Akash
Akash

Reputation: 1726

Why does my stack size differ depending on whether the build is Release or Debug?

Environment: CodeBlocks on Windows 7 64 bit

void recurse(int i)
{
    int a = 9;
    cout<<i<<endl;
    recurse(++i);
}
int main()
{
recurse(1);
return 0;
}

When I run the above code in release mode, it easily exceeds 600k recursion calls, when in Debug mode it fails after 43385 calls.

Any idea why that is happening?

It is not because of the compiler optimizing away the a=9 , without that statement I get 65078 calls in debug mode

Upvotes: 0

Views: 178

Answers (1)

kuroi neko
kuroi neko

Reputation: 8661

A debug build will perform stack overflow checks. To do that, it needs to alocate a bit of stack memory for each function call.

Besides, parameters will also be passed on the stack while a release build will probably use registers.

Upvotes: 1

Related Questions