Re: Required stack size
From: Keith Thompson (kst-u_at_mib.org)
Date: 02/28/05
- Next message: Elinore: "Re: pthread programming for multiprocessor"
- Previous message: Lew Pitcher: "Re: Easy way to access LPT0 printer port without device driver?"
- Next in thread: Kasper Dupont: "Re: Required stack size"
- Reply: Kasper Dupont: "Re: Required stack size"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 28 Feb 2005 21:57:55 GMT
Kasper Dupont <kasperd@daimi.au.dk> writes:
> mkovac@mail386.com wrote:
>>
>> Hi all,
>>
>> I would like to know how much stack memory is used when program is
>> running. Can this be achived in some portable way? At least I would
>> like to know this on Linux. I already managed to get this with the help
>> of gcc instrument functions to check the value of stack pointer when
>> program is entering in functions.
>
> This is the most portable I can come up with:
>
> char *approx_stack_pointer()
> {
> char dummy;
> return &dummy;
> }
>
> Just call this from your main function and when the
> stack is highest, and substract the results. Take
> the numerical value of the result (as you don't know
> if the stack is growing up or down).
(I think you mean absolute value rather than numerical value.)
You should be aware that the C language doesn't guarantee that this is
going to work. Comparing or subtracting pointers that don't point
into the same object (or just past the end of it) invokes undefined
behavior.
Having said that, it's likely to work on many systems; just don't
expect it to be *completely* portable.
-- Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst> San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst> We must do something. This is something. Therefore, we must do this.
- Next message: Elinore: "Re: pthread programming for multiprocessor"
- Previous message: Lew Pitcher: "Re: Easy way to access LPT0 printer port without device driver?"
- Next in thread: Kasper Dupont: "Re: Required stack size"
- Reply: Kasper Dupont: "Re: Required stack size"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|