mirror of
https://github.com/GnoConsortium/gno.git
synced 2025-01-04 22:30:42 +00:00
added a description and example of the _reportStack(3) routine
This commit is contained in:
parent
92ee492794
commit
1157a5530f
@ -1,8 +1,8 @@
|
|||||||
.\" Man page by Devin Reade.
|
.\" Man page by Devin Reade.
|
||||||
.\"
|
.\"
|
||||||
.\" $Id: stack.3,v 1.2 1997/12/08 15:39:11 gdr Exp $
|
.\" $Id: stack.3,v 1.3 1998/03/28 16:47:51 gdr-ftp Exp $
|
||||||
.\"
|
.\"
|
||||||
.TH STACK 3 "11 December 1996" GNO "Library Routines"
|
.TH STACK 3 "26 March 1998" GNO "Library Routines"
|
||||||
.SH NAME
|
.SH NAME
|
||||||
.BR _beginStackCheck ,
|
.BR _beginStackCheck ,
|
||||||
.BR _endStackCheck
|
.BR _endStackCheck
|
||||||
@ -18,6 +18,8 @@ void \fB_beginStackCheck\fR (void);
|
|||||||
int \fB_endStackCheck\fR (void);
|
int \fB_endStackCheck\fR (void);
|
||||||
.br
|
.br
|
||||||
unsigned int \fB_getStackBottom\fR (void);
|
unsigned int \fB_getStackBottom\fR (void);
|
||||||
|
.br
|
||||||
|
void \fB_reportStack\fR (void);
|
||||||
.SH DESCRIPTION
|
.SH DESCRIPTION
|
||||||
The
|
The
|
||||||
.BR _beginStackCheck
|
.BR _beginStackCheck
|
||||||
@ -40,6 +42,19 @@ flag, or the
|
|||||||
.I stacksize
|
.I stacksize
|
||||||
pragma for ORCA/C.
|
pragma for ORCA/C.
|
||||||
.LP
|
.LP
|
||||||
|
Since the procedure used by most programs is to call
|
||||||
|
.BR _beginStackCheck
|
||||||
|
and then immediately register with
|
||||||
|
.BR atexit (3)
|
||||||
|
a function which prints the stack usage on exit, this functionality has been
|
||||||
|
provided by
|
||||||
|
.BR _reportStack ;
|
||||||
|
just call
|
||||||
|
.BR _reportStack
|
||||||
|
immediately after
|
||||||
|
.IR main
|
||||||
|
and nothing else is required.
|
||||||
|
.LP
|
||||||
The
|
The
|
||||||
.BR _getStackBottom
|
.BR _getStackBottom
|
||||||
routine returns the lowest direct page address which can legally be used
|
routine returns the lowest direct page address which can legally be used
|
||||||
@ -88,28 +103,21 @@ The
|
|||||||
routine itself uses stack space, especially when printing out error
|
routine itself uses stack space, especially when printing out error
|
||||||
messages. Ensure you allow at least 100 bytes extra to allow for this.
|
messages. Ensure you allow at least 100 bytes extra to allow for this.
|
||||||
.SH EXAMPLE
|
.SH EXAMPLE
|
||||||
An easy way to use the first two routines is to make use of the
|
The most common way to make use of these routines is to call
|
||||||
.BR atexit (3)
|
.BR _reportStack
|
||||||
function, so that you don't have to determine all the possible exit
|
as your first step in
|
||||||
points of your program. The GNO base sources make use of the
|
.IR main .
|
||||||
|
The GNO base sources make use of the
|
||||||
macro __STACK_CHECK__ to control whether or not this check is done.
|
macro __STACK_CHECK__ to control whether or not this check is done.
|
||||||
You may want to use the same macro.
|
You may want to use the same macro.
|
||||||
.nf
|
.nf
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <gno/gno.h>
|
#include <gno/gno.h>
|
||||||
|
|
||||||
#ifdef __STACK_CHECK__
|
|
||||||
void cleanup (void) {
|
|
||||||
fprintf(stderr,"Stack Usage: %d bytes\n", _endStackCheck());
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void main (int argc, char **argv) {
|
void main (int argc, char **argv) {
|
||||||
|
|
||||||
#ifdef __STACK_CHECK__
|
#ifdef __STACK_CHECK__
|
||||||
_beginStackCheck();
|
_reportStack();
|
||||||
atexit(cleanup);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
... <program continues> ...
|
... <program continues> ...
|
||||||
|
Loading…
Reference in New Issue
Block a user