Related articles |
---|
Wanted: a program that calulates the maximal stack depth samuel@nada.kth.se (1992-04-06) |
Re: Wanted: a program that calulates the maximal stack depth russw@cs.utexas.edu (1992-04-09) |
Re: Wanted: a program that calulates the maximal stack depth bliss@sp64.csrd.uiuc.edu (1992-04-09) |
Re: Wanted: a program that calulates the maximal stack depth hays@ssd.intel.com (1992-04-09) |
Re: Wanted: a program that calulates the maximal stack depth pbk@arkesden.Eng.Sun.COM (1992-04-10) |
Re: Wanted: a program that calulates the maximal stack depth eifrig@beanworld.cs.jhu.edu (1992-04-10) |
Re: Wanted: a program that calulates the maximal stack depth samuel@nada.kth.se (1992-04-11) |
Newsgroups: | comp.compilers |
From: | bliss@sp64.csrd.uiuc.edu (Brian Bliss) |
Keywords: | storage |
Organization: | UIUC Center for Supercomputing Research and Development |
References: | 92-04-029 92-04-039 |
Date: | Thu, 9 Apr 1992 17:49:34 GMT |
samuel writes:
> I'm developing an application where the use of stack space is crucial.
Assumming you have a language which supports stack-allocated locals, C in
this example, why not just keep track of the min/max address of a local
var upon subroutine entry? It won't work very well if you are dynamically
allocating large arrays on the stack in leaf procedures, but usually
provides a very good approximation. I used something similar to this to
help debug a multitasking package I wrote (when modifying the context
switch routine, where the stacks kept getting all messed up).
#ifdef STACK_CHECK
char *main_address;
char *min_address;
#endif
main () {
#ifdef STACK_CHECK
char ch;
main_address = min_address = &ch;
#endif
.
.
.
printf ("stack usage = 0x%x\n", main_address - min_address);
/* assume stack grows downward */
}
then in each subroutine, put:
int sub () {
#ifdef STACK_CHECK
char ch;
if (&ch < min_address) min_address = &ch; /* assume stack grows downward */
#endif
.
.
.
}
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.