PRODUCT : Borland C++ NUMBER : 734 VERSION : 2.0 OS : DOS DATE : October 19, 1993 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 #include 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 clrscr(); PRODUCT : Borland C++ NUMBER : 734 VERSION : 2.0 OS : DOS DATE : October 19, 1993 PAGE : 2/2 TITLE : Determining Stack Size #if defined (__COMPACT__) || defined (__LARGE__) || defined (__HUGE__) ret = 16 * (*((unsigned *)_heapbase + 1) - _SS) - 16; #else ret = *((unsigned *) _heapbase + 1 ) - __brklvl - 1; #endif return ret; } DISCLAIMER: You have the right to use this technical information subject to the terms of the No-Nonsense License Statement that you received with the Borland product to which this information pertains.