estimating stack size

is this appropriate code for estimating size of the stack?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
unsigned long int hi;

void deeplynested(){ unsigned long int lo, len;
lo = (unsigned int) &lo;
len = hi - lo;
printf("stack is about %d bytes\n", len );
}

void main()
{
   int mainvar; 
   hi = (unsigned long int) &mainvar;
   deeplynested();
//...
}


it returnes me 65836 bytes on my WindowsXP Home Edition
Last edited on
Your global variable hi is not going to be on the stack, so the result your code gives could be a bit odd (comparing the location of a stack variable with a global stored in one of the data segments)

You could look at StackWalk64 (works with 32bit as well as 64bit, see MSDN for details)

Or if you want to go the inline assembly + ebp/esp route, check out
http://stackoverflow.com/questions/3845745/faster-than-stackwalk

Andy
Last edited on
Topic archived. No new replies allowed.