Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- __thread void* stack_start;
- __thread long stack_max_size = 0L;
- void check_stack_size() {
- // address of 'nowhere' approximates end of stack
- char nowhere;
- void* stack_end = (void*)&nowhere;
- // may want to double check stack grows downward on your platform
- long stack_size = (long)stack_start - (long)stack_end;
- // update max_stack_size for this thread
- if (stack_size > stack_max_size)
- stack_max_size = stack_size;
- }
- void thread_proc() {
- char nowhere;
- stack_start = (void*)&nowhere;
- // do stuff including calls to check_stack_size()
- // in deeply nested functions
- // output stack_max_size here
- }
Add Comment
Please, Sign In to add comment