Stack usage on recursive call |
Post Reply |
Author | |
znakeeye
Senior Member Joined: 26 July 2006 Status: Offline Points: 1672 |
Post Options
Thanks(0)
Posted: 29 November 2009 at 5:08pm |
VS 2008 SP1.
Consider this function: void foo(int x)
{
foo(x + 1);
}
If I add a parameter "int y", I would expect the stack usage to increase by 4 bytes. However, in my case (in debug mode) it increases with 72 bytes.
Can somebody please explain this? 68 extra bytes is a LOT! :(
Sample program: uploads/20091203_064021_StackBomb.zip
|
|
mgampi
Senior Member Joined: 14 July 2003 Status: Offline Points: 1201 |
Post Options
Thanks(0)
|
Additional stack checking code???
|
|
Martin Product: Xtreme Toolkit v 22.1.0, new Projects v 24.0.0 Platform: Windows 10 v 22H2 (64bit) Language: VC++ 2022 |
|
znakeeye
Senior Member Joined: 26 July 2006 Status: Offline Points: 1672 |
Post Options
Thanks(0)
|
Sure, but 68 bytes?! It makes it hard to debug my recursive function, since it blows the stack. 6 parameters yields 432 bytes, lol...
In Release-mode the recursive call is optimized away completely, so there is no need in rewriting my algorithm.
|
|
znakeeye
Senior Member Joined: 26 July 2006 Status: Offline Points: 1672 |
Post Options
Thanks(0)
|
Please see attached sample. It demonstrates this.
It's totally sick! :(
|
|
jimmy
Senior Member Joined: 11 November 2003 Location: Austria Status: Offline Points: 515 |
Post Options
Thanks(0)
|
Hi,
Every parameter need 4 Byte. CALL need 4 Byte. Save EBP need 4 Byte. Save some other register need 3*4 Byte. "Full runtime check" need 160 Byte. You can disable it. if i have only 1 parameter it need 108 Byte. i calculate 4 Byte parameter 4 Byte call 4 Byte save ebp 4 byte save this pointer 8 byte for local variables --------- 24 Byte 108 - 24 = 84 Byte too much ??? ================== i don't know more. Jimmy |
|
znakeeye
Senior Member Joined: 26 July 2006 Status: Offline Points: 1672 |
Post Options
Thanks(0)
|
I think I'll disable runtime check in this particular cpp file. In optimized release-mode the stack usage is 0 bytes (!). Do you know a #pragma to disable runtime check? |
|
jimmy
Senior Member Joined: 11 November 2003 Location: Austria Status: Offline Points: 515 |
Post Options
Thanks(0)
|
Hi,
Start Visual Studio, press F1 search #pragma , see runtime_checks and click it. Than you see this #pragma runtime_checks( "", off ) Jimmy |
|
jimmy
Senior Member Joined: 11 November 2003 Location: Austria Status: Offline Points: 515 |
Post Options
Thanks(0)
|
See also
#pragma check_stack([ {on | off}] ) #pragma check_stack{+ | –} Jimmy |
|
znakeeye
Senior Member Joined: 26 July 2006 Status: Offline Points: 1672 |
Post Options
Thanks(0)
|
Thanks, but these have no effect in debug-mode, as it seems :/
|
|
Post Reply | |
Tweet
|
Forum Jump | Forum Permissions You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |