home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Black Box 4
/
BlackBox.cdr
/
progc
/
bchelp10.arj
/
TI734.ASC
< prev
next >
Wrap
Text File
|
1991-09-23
|
2KB
|
133 lines
PRODUCT : Borland C++ NUMBER : 734
VERSION : 2.0
OS : DOS
DATE : September 23, 1991 PAGE : 1/2
TITLE : Determining Stack Size
/************************************************************************
NEAR MEMORY MODELS:
In the near memory models the stack resides in the data segment.
It begins at the end of DGROUP and grows down in memory towards
SS & DS. The variable __brklvl always marks the top of the heap.
The stack is allowed to grow until SP reaches __brklvl at which
time a stack overflow will be generated if stack checking is
turned on else the heap will be overwritten as the stack grows.
FAR MEMORY MODELS:
The stack starts in high memory just prior to _heapbase and grows
down towards SS.
This code example shows how to check the size of the stack at run
time.
written by:
Jerry Shockley 9/18/91
************************************************************************/
#include <stdio.h>
#include <conio.h>
unsigned long stack();
void main()
{
unsigned long size = stack();
printf("\nStack size = %lu",size);
}
unsigned long stack()
{
unsigned long ret;
extern unsigned long _heapbase; //Beginning of the far heap
extern unsigned __brklvl; //End of the near heap
PRODUCT : Borland C++ NUMBER : 734
VERSION : 2.0
OS : DOS
DATE : September 23, 1991 PAGE : 2/2
TITLE : Determining Stack Size
clrscr();
#if defined (__COMPACT__) || defined (__LARGE__) || defined
(__HUGE__)
ret = 16 * (*((unsigned *)_heapbase + 1) - _SS) - 16;
#else
ret = *((unsigned *) _heapbase + 1 ) - __brklvl - 1;
#endif
return ret;
}