[comp.lang.c] shrinking the heap in small-model MS C : MYSTERIOUS ANSWER

rreiner@yunexus.YorkU.CA (Richard Reiner) (09/20/90)

A while ago I asked how to prevent a small-model MS C 5.1 program from
grabbing and keeping a full 64K data segment (this was because my
program's task was to do a little processing and then spawn(), and it
was hogging 85K when it had nearly no data and only 25K of code).

All attempts to do this using sbrk() failed, as did attempts using
MS-LINK switches including /CPARMAXALLOC.

Today, however, I got an answer from one Dan Cooperstock here in
Toronto: compile the program as usual, then do

	EXEMOD foo.exe -stack n -min 0 -max 0

where foo.exe is the executable, and n is whatever stack you think you
need.  This gives two error messages, but *it works*: suddenly my code
only takes 30K above its spawned child.

Now, this shouldn't work: according to the MS C docs, EXEMOD's -max is
equivalent to MS-LINK's /CPARMAXALLOC, and the documentation of that
switch says you can't force the allocation below 64K.

So what's going on?  Why does this work?  Do the MS C 6.0 docs clear
this up?

--richard