[net.micro.pc] DOS memory management

toms@oakhill.UUCP (Thomas Spohrer) (10/23/86)

     I am very interested in finding out just how DOS manages
memory using function calls $48, $49, and $4A (I think).
 
     1.)  If a program requests several blocks of storage and then
          gives one of the first ones it requested back will DOS
          ever use this space again to load another program or will
          it only use it on subsequent memory requests that are
          smaller than the empty block?
 
     2.)  If several blocks of memory that were requested individually
          are freed but they were contigious will DOS combine them into
          a large block that can be gotten with a request that is
          bigger than the individual pieces were, or will these blocks
          always be treated separatly and therefore create fragments?
          Also, if a program shrinks a block that it owned, will the
          released space be used on a subsequent request for a larger
          chunk than was released (assuming space after the released
          chunk is free also)?
 
     3.)  What happens if a (probably poorly designed) program (#2)
          does a jump to a memory resident program (#1) that frees the
          block of memory that program #2 was in, and then the
          memory resident program tries to grow a block it had
          requested previously for data over the area where program #2
          used to reside.  In other words program #2 is a bootstrap
          program that tells the memory resident program to get more
          memory for data but it wants a contigious chunk so it
          needs the are where the bootstrap program got loaded as well.
 
          Hint: I tried this sequence and it seemed to work fine.
                The memory resident program did not get any errors
                from DOS when it released program #2s memory or when
                it requested to grow its block over the area where
                program #2 was.  After this sequence of events
                CHKDSK reported the proper amount of memory in the
                system and the proper amount of memory free.  However,
                after this if try to run Wordstar I get an Insufficient
                memory error, and CHKDSK NOW not only thinks I have
                very little memory free but it has also lost track of
                how much memory is in the system overall.  Eventhough
                at first sight, it seems that everything is OK,
                DOS must be very confused about what memory is where.
 
     I would appreciate any help anyone could offer on any of these
questions.  Maybe there is a better way to accomplish what I am
trying to do in question #3.  In summary, what I am trying to do
is to dynamiclly grow and shrink the space an interrupt
handler owns to keep its data structures in.  This solution loads
another program to tell the handler what to do.  Any more eligant
suggestions would be much appreciated.  Watching the keyboard int
has the draw back that I do not know how to tell if any other programs
are loaded and running, and I am leary of calling DOS from the
int handler to report errors or messages.
                                 Thanks in advance.


=============================================================================

Motorola Semiconductors                     Tom Spohrer
Austin, Texas                {seismo,gatech,ihnp4}!ut-sally!oakhill!toms