[comp.sys.ibm.pc.programmer] Increase run-time stack size

swh@hpcupt1.HP.COM (Steve Harrold) (06/27/90)

>>> Please give me some hints to avoid stack overflow. As I recall,
>>> one can put a stack size in main() file or use switches to specify 
>>> stack size during linking.
-----------------

Things that seem to go into the stack with Microsoft C programs include the
environment table (in some memory models); thus you might want to reduce
the number of superfluous variables in the DOS environment.

Also check into the EXEMOD program (it comes with Microsoft C and other MS
products).  You can use it to alter the size of the stack of an already
existing .EXE file.  

weisen@eniac.seas.upenn.edu (Neil Weisenfeld) (06/29/90)

In article <32559@ut-emx.UUCP> ycy@walt.cc.utexas.edu (Joseph Yip) writes:
>Hi,
>
>I have not been programming pc for some time. I am using Microsoft C
>Version 5 to compiler some C code. I run into stack overflow  during
>run-time. The problem is due to the size of arrays I declare.
>
>Please give me some hints to avoid stack overflow. As I recall,
>one can put a stack size in main() file or use switches to specify 
>stack size during linking.
>
>Thank you.
>
>- Joseph

You can link with the /STACK option:
  link xx.obj yyy.obj,,,zzz.lib/STACK:10000;

will give you a 10000 byte stack space.  You can also use the EXEMOD
program to expand the stack size of an executable without re-linking.

Under MSC 6.00, I think that EXEMOD has a different name.

-Neil

(just my hopefully correct $0.02)


=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Neil I.  Weisenfeld                    | InterNet: weisen@eniac.seas.upenn.edu
Dept. of Computer and Info. Sciences   | USPS: I dunno, I'm moving...
University of Pennsylvania             | PENNmail: Don't even try it...
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

gordon@osiris.cso.uiuc.edu (John Gordon) (06/29/90)

	In Turbo C, you can set the _stklen variable to the # of bytes
desired.


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

stever@Octopus.COM (Steve Resnick ) (07/02/90)

In article <100010006@hpcupt1.HP.COM> swh@hpcupt1.HP.COM (Steve Harrold) writes:
>>>> Please give me some hints to avoid stack overflow. As I recall,
>>>> one can put a stack size in main() file or use switches to specify 
>>>> stack size during linking.
>-----------------
>
>Things that seem to go into the stack with Microsoft C programs include the
>environment table (in some memory models); thus you might want to reduce
>the number of superfluous variables in the DOS environment.
>

WHAT?????? The environment is in the data segment (as opposed to the stack
segment which may be the same segment but is addressed with SS as opposed to
DS). Changing the size of your environment should have no affect on running
programs. Stricly speaking the environment is not part of DOS. It's part of
COMMAND.COM and therefore should not affect the running of programs. The stack
by convention is allocated based on information in the .EXE header. There are
vendors who do not comply with this (Borland for instance) but Microsoft does.
That is what the EXEMOD and EXEHDR utilities are for. To allocate the stack
size you want, use the /ST:xxxx option for the MS linker (most other linkers
have a similar option, too). This will allocate the required number of bytes 
(indicated in xxxx) for the stack.
 
 Cheers!

 Steve

-- 
--------------------------------------------------------------------------------
Steve Resnick -<stever@octopus.COM apple!octopus!stever sun!vsi1!octopus!stever>
408/241-1533 Process Scientific, Inc.
"0x2B|~0x2B THAT is the question!"

dhinds@portia.Stanford.EDU (David Hinds) (07/02/90)

In article <1990Jul2.011448.19220@Octopus.COM> stever@octopus.UUCP (Steve Resnick ) writes:
>In article <100010006@hpcupt1.HP.COM> swh@hpcupt1.HP.COM (Steve Harrold) writes:
>>Things that seem to go into the stack with Microsoft C programs include the
>>environment table (in some memory models); thus you might want to reduce
>>the number of superfluous variables in the DOS environment.
>>
>WHAT?????? The environment is in the data segment (as opposed to the stack
>segment which may be the same segment but is addressed with SS as opposed to
>DS). Changing the size of your environment should have no affect on running
>programs. Stricly speaking the environment is not part of DOS. It's part of
>COMMAND.COM and therefore should not affect the running of programs.

Not quite true - first, the environment IS managed by DOS and is not just a
feature of COMMAND.COM.  Second, since the environment is put in kind of an
inconvenient place (in another segment), some compilers make a copy of it
to make accessing it easier.  I know the Topspeed C compiler does this, and
I bet Microsoft does as well.  It might stick it in the stack (why?  I don't
know).  So, the size of the environment does matter.  I wouldn't expect to
get much mileage out of it, though - maybe 1K if it is really big?

 -David Hinds
  dhinds@popserver.stanford.edu