home *** CD-ROM | disk | FTP | other *** search
/ BCI NET / BCI NET Dec 94.iso / archives / programming / source / virt.lha / Virtual.doc < prev    next >
Encoding:
Text File  |  1992-11-14  |  4.8 KB  |  140 lines

  1.                   Virtual-Memory Documentation
  2.                   ============================
  3.  
  4. GENERAL
  5. -------
  6. What is Virtual Memory (VM) ?
  7.  VM refers to the memory available to a program which exists either in Primary
  8.  Memory (Physical) or in Secondary Memory (Disk). Normally VM space is larger
  9.  Than physical space and it is the task of the processor/OS to switch data
  10.  to and from the disk.
  11.  On 386/486 systems VM exists when working in what is called Protected Mode , 
  12.  The Amiga doesn't support such capabilities , and my functions try to create
  13.  such environment.
  14.  The abstraction used is that of Segments - Blocks of memory of varying size
  15.  which all exist in VM. When you need to use a segment it is mapped to physical
  16.  memory starting at a specific Base Address. If there is no room for a segment
  17.  other segments will be swapped to disk to make room.
  18.  An important concept is that of a PRESENT segment. such segment resides in
  19.  physical memory and has a valid Base Address.
  20.  
  21. FUNCTIONS
  22. ---------
  23. *  InitVirtualMem --
  24.     Initialize a VirtMem structure and allocate physical memory.
  25.     Note that more than one VM space can be created.
  26.  
  27.     BOOL InitVirtualMem(VM,FName,VirtSize,PhysSize,SegNum)
  28.  
  29.    Input -
  30.     struct VirtMem *VM  -- A pointer to an empty VirtMem structure.
  31.     char const *FName   -- A pointer to the Disk file name used as swap file.
  32.     ULONG VirtSize      -- Size of virtual memory in bytes (currently ignored).
  33.     ULONG PhysSize      -- Size of physical memory. Allocated by function.
  34.     USHORT SegNum       -- Max number of segments.
  35.    Output -
  36.     returns TRUE if successful , FALSE otherwise.
  37.  
  38.  
  39. *  FreeVirtMem --
  40.     Free memory associated with a VM space.
  41.  
  42.     void FreeVirtMem(VM)
  43.  
  44.    Input -
  45.     struct VirtMem *VM  -- A pointer to an initialized VirtMem structure.
  46.    Output -
  47.     returns nothing.
  48.  
  49.  
  50. *  CreateSegment --
  51.     Add a segment to the system. The segment's contents are unintialized.
  52.     The Segment IS NOT made present (mapped to physical memory).
  53.  
  54.     struct SegEntry *CreateSegment(VM,Size,Pri)
  55.  
  56.    Input -
  57.     struct VirtMem *VM  -- A pointer to an initialized VirtMem structure.
  58.     ULONG Size          -- Size of Segment (must be smaller than Physical
  59.                                              memory size).
  60.     SHORT Pri           -- Priority of the segment. Range -128 to 127.
  61.    Output -
  62.     returns pointer to SegEntry if sucessful , NULL otherwise.
  63.  
  64.  
  65. *  Access --
  66.     Make a Segment present in physical memory as a neccessary step before
  67.     A read/write operation to this segment.
  68.  
  69.     BOOL Access(VM,Seg)
  70.  
  71.    Input -
  72.     struct VirtMem *VM    -- A pointer to an initialized VirtMem structure.
  73.     struct SegEntry *Seg  -- A pointer to a segment that is to be made present.
  74.    Output -
  75.     TRUE is successful , FALSE otherwise.
  76.  
  77.  
  78. MACROS
  79. ------
  80.  
  81. NORMALIZE(Seg,Offset) -- Create a physical address from a Base Address in a 
  82.                          Segment and an Offset.
  83. OFFSET(Seg,Full)      -- Calculate an offset from a physical address and the
  84.                          Base Address in the Segment.
  85. DIRTY(Seg)            -- Make Segment DIRTY. A Dirty segment is one that has
  86.                          been changed.
  87. PRESENT(Seg)          -- Check whether a Segment is present.
  88.  
  89.  
  90. SWAPPING
  91. --------
  92. When a segment has no room other segments are swapped to disk.
  93. The algorythm for swapping is simple and not very intelligent.
  94. It goes as follows :
  95.  Start Loop
  96.   Find room for the requested segment
  97.   if successful make segment present and return.
  98.   if not find a present segment which has the lowest priority and remove it.
  99.    (if more than one segment has a low priority remove the one that was accessed
  100.     furthest in the past).
  101.  End Loop.
  102.  
  103. To make the system efficient do the following :
  104. * Set high priority for segments that are accessed regularily.
  105. * Use segment sizes that are whole divisions of physical size.
  106.    e.g with 32K physical memory use 8K/16K segment sizes.
  107.  
  108.  
  109. NOTES
  110. -----
  111. * When using pointers work with offsets since absolute addresses change
  112.   every time you swap a segment.
  113. * Remember to set the Dirty bit with the DIRTY macro when you write to
  114.   a segment so it will be updated on disk.
  115. * The system doesn't check for available space on disk. make sure you
  116.   have enough space (Disk Space>=Virtual Size).
  117.  
  118. COMPILING
  119. ---------
  120. The code is written for Aztec C5.2. It should also compile on Lattice.
  121. I use a pre-include file which contains func1_3.h and pragma1_3.h so you
  122. might need to #include these files.
  123. You can either add Virtual.c to your makefile or link the Virtual.o module
  124. if you use Aztec C.
  125.  
  126.  
  127. LEGAL STUFF
  128. -----------
  129. The program is Gift-Ware that is if you like it you can send money, software
  130.  poems or anything you like as a gift.
  131. It can be used in any program commercial or otherwise with no charge.
  132.  
  133.  
  134. ------------
  135. Amit Fridman
  136. s2449558@techst02.discus.technion
  137. Eshkol 15 Yehud
  138. ISRAEL 56000
  139. ------------
  140.