[net.micro.pc] Removing a memory-resident program -- Help

drk@well.UUCP (Doug Kaye) (11/19/85)

When removing a previously loaded memory-resident program we cannot
recover all of the memory.  It appears that DOS keeps 64 bytes each
time.  What's the trick to getting back ALL of your memory when
removing a resident program??
	Doug Kaye
	Rational Data Systems
	ihnp4!hplabs!well!drk

bb@oliveb.UUCP (Bart Berger) (11/21/85)

> When removing a previously loaded memory-resident program we cannot
> recover all of the memory.  It appears that DOS keeps 64 bytes each
> time.  What's the trick to getting back ALL of your memory when
> removing a resident program??
> 	Doug Kaye
> 	Rational Data Systems
> 	ihnp4!hplabs!well!drk

I believe that 64 bytes is the copy of the environment table that MS-DOS
makes for each program.  The trick is:  before releasing the program's
memory, release the environment table's memory.  The segment address of
the environment table is at offset 2C in the Program Segment Prefix; pass
that segment address to MS-DOS function 49h to release the environment
table space.  (Caveat:  I haven't tried this yet.)

							Bart Berger
        						...!oliveb!bb

jnw@mcnc.UUCP (John White) (11/21/85)

> When removing a previously loaded memory-resident program we cannot
> recover all of the memory.  It appears that DOS keeps 64 bytes each
> time.  What's the trick to getting back ALL of your memory when
> removing a resident program??
> 	Doug Kaye
> 	Rational Data Systems
> 	ihnp4!hplabs!well!drk

A memory-resident program has two blocks associated with it. There is the
main block, and the environment block. The segment of the environment
block is pointed to by offset 2C of the Program Segment Prefix.
Freeing both blocks with the dealloc call will recover all memory and
completely remove the memory-resident program. Whenever I write a
terminate-and-stay-resident program I have an alternate invocation
of that command to remove the program. I find this quite usefull.
(Actually, I usually free the environment block just before the
terminate-and-stay-resident system call, and so I only have to free
the main block to remove the program. Either way works.)