Category : C Source Code
Archive   : BCPPTECH.ZIP
Filename : TI734.ASC

 
Output of file : TI734.ASC contained in archive : BCPPTECH.ZIP







PRODUCT : Borland C++ NUMBER : 734
VERSION : 2.0
OS : DOS
DATE : February 25, 1992 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














PRODUCT : Borland C++ NUMBER : 734
VERSION : 2.0
OS : DOS
DATE : February 25, 1992 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;
}









































  3 Responses to “Category : C Source Code
Archive   : BCPPTECH.ZIP
Filename : TI734.ASC

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/