code_junkie

Checking available stack size in C

Nov 10th, 2011
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.37 KB | None | 0 0
  1. size_t top_of_stack;
  2.  
  3. void Main()
  4. {
  5. int x=0;
  6. top_of_stack = (size_t) &x;
  7.  
  8. do_something_very_recursive(....)
  9. }
  10.  
  11. size_t SizeOfStack()
  12. {
  13. int x=0;
  14. return top_of_stack - (size_t) &x;
  15. }
  16.  
  17. man getrusage
  18.  
  19. int main (void)
  20. {
  21. struct rlimit limit;
  22.  
  23. getrlimit (RLIMIT_STACK, &limit);
  24. printf ("nStack Limit = %ld and %ld maxn", limit.rlim_cur, limit.rlim_max);
  25. }
Add Comment
Please, Sign In to add comment