system() command

Peter Holzer hp at vmars.tuwien.ac.at
Sun Feb 10 08:16:42 AEST 1991


tp1l+ at andrew.cmu.edu (Thomas W. Pope) writes:


>   I am writing a short program to put into my autoexec file, allowing me
>to select a shorter autoexec by hitting a key.  For this I tried to use the
>system() command to run either of two batch files.  The command works fine, but
>the program stays resident after that call, adding 64k to my memory usage.
>   The Turbo C manuals say that the system command will run batch files fine,
>but it seems to terminate withour clearing memory every time I try it...  Does
>anyone know how I could make these calls from my program???  I have tried the
>following calls:


>   system(default)              system(call default)
Shouldn't this be:
system ("default"); and system ("call default"); ?

Apart from that, does your batchfile invoke any TSRs? If it does, it
will fragment your memory, and DOS will report only the largest chunk as
free memory, although it can use the rest as well.

Your memory looks something like that (low addresses at the bottom:

	    
	Command.com
	DOS

Start your program:

	yourprog.exe
	Command.com
	DOS

system ("default"):

	command.com -c default
	yourprog.exe
	Command.com
	DOS

default now executes some TSR, e.g. sidekick:

	sidekick
	command.com -c default
	yourprog.exe
	Command.com
	DOS

default terminates, thus command.com and system terminate, too:

	sidekick
	<empty space>
	yourprog.exe
	Command.com
	DOS

Then your program terminates:

	sidekick
	<empty space>
	<empty space>
	Command.com
	DOS

So you have sidekick floating around somewhere in mid-memory, with a
whole of ~64kB below it and a larger hole above it. DOS will always use
the largest available whole and it cannot split a program to use
multiple wholes so you have wasted those 64kB :-(.

--
|    _  | Peter J. Holzer                       | Think of it   |
| |_|_) | Technical University Vienna           | as evolution  |
| | |   | Dept. for Real-Time Systems           | in action!    |
| __/   | hp at vmars.tuwien.ac.at                 |     Tony Rand |



More information about the Comp.lang.c mailing list