Programming
Home Up Feedback Contents Search

                  WRITING PROGRAMS THAT USE EXPANDED MEMORY                   

     In order  to use expanded memory, applications must perform these
     steps in the following order:

     1.   Determine if EMM is installed.
     2.   Determine if enough expanded  memory  pages  exist  for your
          application. (Function 3)
     3.   Allocate expanded memory pages. (Function 4 or 18)
     4.   Get the page frame base address. (Function 2)
     5.   Map in expanded memory pages. (Function 5 or 17)
     6.   Read/write/execute data in expanded memory,  just  as  if it
          were conventional memory.
     7.   Return expanded memory pages to expanded memory  pool before
          exiting. Function 6 or 18)

                            Programming Guidelines                            

     The following section contains guidelines for programmers writing
     applications that use EMM.

     A)   Do not put a program's stack in expanded memory.

     B)   Do not replace  interrupt  67h. This is the interrupt vector
          the  EMM  uses.  Replacing  interrupt  67h  could  result in
          disabling the Expanded Memory Manager.

     C)   Do not  map  into  conventional  memory  address  space your
          application doesn't own. Applications that  use  the  EMM to
          swap  into  conventional  memory  space, must first allocate
          this space  from  the  operating  system.  If  the operating
          system is not aware that a region of memory it manages is in
          use,  it  will  think  it  is  available.  This  could  have
          disastrous results. EMM should  not  be  used  to "allocate"
          conventional   memory.

          DOS is the proper manager of conventional memory space.  EMM
          should  only  be used  to swap  data in  conventional memory
          space previously allocated from DOS.

     D)   Applications that plan on using  data  aliasing  in expanded
          memory  must  check  for  the  presence  of  expanded memory
          hardware. Data aliasing occurs when mapping one logical page
          into two  or more mappable segments. This makes one 16K-byte
          expanded memory page appear to  be in more than one 16K-byte
          memory address space. Data aliasing is  legal  and sometimes
          useful  for  applications.  Software-only  expanded   memory
          emulators cannot perform  data  aliasing.  A  simple  way to
          distinguish  software emulators from actual expanded  memory
          hardware is  to attempt data aliasing and check the results.
          For example,  map one logical page into four physical pages.
          Write to physical page 0. Read physical pages 1-3 to  see if
          the data is there as well.  If  the data appears in all four
          physical  pages, then expanded memory hardware is  installed
          in the system, and data aliasing is supported.

     E)   Applications  should always return expanded memory pages  to
          the expanded memory manager  upon  termination.  These pages
          will be made available for other  applications.  If unneeded
          pages are not  returned  to the expanded memory manager, the
          system could run out  of  expanded  memory pages or expanded
          memory handles.

     F)   Terminate and stay resident  programs  (TSRs)  should always
          save the state of  the  map  registers before changing them.
          Since TSRs may  interrupt  other programs which may be using
          expanded memory, they must not  change the state of the page
          mapping registers without first saving them. Before exiting,
          TSRs  must  restore  the  state  of the map  registers.  The
          following sections  describe  the  three  ways  to  save and
          restore the state of the map registers.

          1)   Save Page Map and Restore Page Map (Functions 8 and 9).
               This  is the simplest of the  three  methods.  The  EMM
               saves  the  map  register  contents  in  its  own  data
               structures -- the application does not need  to provide
               extra storage locations for  the  mapping  context. The
               last mapping context to be  saved,  under  a particular
               handle, will be restored  when  a  call to Restore Page
               Map  is issued with the same  handle.  This  method  is
               limited to one  mapping  context  for  each  handle and
               saves the context for only LIM  standard  64K-byte page
               frames.

          2)   Get/Set Page Map (Function  15).  This  method requires
               the application  to  allocate  space  for  the  storage
               array. The EMM saves  the  mapping  context in an array
               whose address  is passed to the EMM. When restoring the
               mapping context with this method, an application passes
               the address of an  array  which  contains  a previously
               stored mapping context. This method is preferable if an
               application needs to do more  than  one  save  before a
               Restore. It provides  a mechanism for switching between
               more than one mapping context.

          3)   Get/Set  Partial  Page  Map  (Function 16). This method
               provides a way for saving a partial mapping context. It
               should be used when  the  application  does not need to
               save the context of all mappable memory.  This function
               also requires that the storage  array  be  part  of the
               application's data.

     G)   All functions using pointers to  data  structures  must have
          those data structures in memory  which  will  not  be mapped
          out. Functions 22 and 23 (Alter  Map  & Call and Alter Map &
          Jump) are the only exceptions.
 
See Also Specifications Locating Func/40h Func/4Eh/00h Errors History


Copyright © 1985 to 2003 Beta Systems                            Last modified: Wednesday April 30, 2003 .