[comp.lang.c] Turbo-C stack problem

sun@me.utoronto.ca (Andy Sun Anu-guest) (07/20/90)

Hi,

Does anybody out there know if I can alter the stack size (increase it to be
specific) in Turbo C? And if yes, how can it be done? I got a stack overflow
error in my program (compiled using small model) and after I flipped through
all the manuals, I still cannot find anything that allow me to change the
stack size (there is a global variable called _stklen, but it doesn't mention
exactly how it is used). I CANNOT use anything higher than small model since
I will have a memory allocation error (insufficient memory). BTW, I am using
Turbo C version 1.5. Any suggestion and advises are welcome.

Andy

_______________________________________________________________________________
Andy Sun                            | Internet: sun@me.utoronto.ca
University of Toronto, Canada       | UUCP    : ...!utai!me!sun
Dept. of Mechanical Engineering     | BITNET  : sun@me.utoronto.BITNET

unicorn@uxh.cso.uiuc.edu (07/20/90)

Andy,

  I had a similiar problem once also, but I was able to reduce other memory
use so I didn't have to change the stack size.  This may totaly off-base,
but here is what i think is going on.

  The stack size is set by the program, not by the compiler.  The compiler
sets up the memory size and usage.  It only defines the top of the stack,
not the bottom.  The variable _stklen is used by the initiating code to
calculate the pointer where the end of stack is at.  So I think! that
it just needs something like,

#define STACKSIZE 10240

extern unsigned _stklen = STACKSIZE;

main()
{
.
.
.
}


  I never actually tried this, but it kind of makes sense (I hope!).
Since _stklen becomes a public symbol after compilation, the initiating
code can easily look at it in the data segment.

I hope that this helps (and works!!).  Let me know if you learn anything
else about this.

Harry E. Miller
unicorn@uxh.cso.uiuc.edu
Smile! - The Unicorn is watching you!!

gordon@osiris.cso.uiuc.edu (John Gordon) (07/20/90)

	To change the stacklength, it is very easy:  just say

		_stklen = (num of bytes desired) in your program.

		example:  _stklen = 48000;

	NOTE: I think it is required to set it globally, not locally.
		Also, I did it in 2.0, not 1.5.


---
John Gordon
Internet: gordon@osiris.cso.uiuc.edu        #include <disclaimer.h>
          gordon@cerl.cecer.army.mil       #include <clever_saying.h>
GEnie:    j.gordon14