home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / library / dos / nicol / sti_vm / sti_vm.txt < prev    next >
Encoding:
Text File  |  1990-10-20  |  20.1 KB  |  727 lines

  1.  
  2.  
  3.  
  4.         
  5.         
  6.         
  7.         
  8.         
  9.         
  10.         
  11.         
  12.         
  13.         
  14.         
  15.         
  16.         
  17.         
  18.                            VIRTUAL MEMORY MANAGEMENT SYSTEM 1.0
  19.         
  20.                                For Turbo Pascal Version 5.0
  21.         
  22.         
  23.         
  24.         
  25.         
  26.         
  27.         
  28.         
  29.         
  30.         
  31.         
  32.         
  33.                                   Copyright 1990, 1991 By
  34.         
  35.                              Software Technology International
  36.         
  37.                                     All Rights Reserved
  38.         
  39.         
  40.         
  41.         
  42.         
  43.         
  44.         
  45.         
  46.         
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.                                             1
  65.  
  66.                                           NOTICE
  67.                                           ------
  68.                   
  69.  
  70.         
  71.                      All parts of this manual and the accompanying  soft-
  72.                   ware  are  copyrighted material. You, as  a  registered 
  73.                   user, are granted permission to make as many copies  of 
  74.                   the  software, or manual, as you wish, as long as  they 
  75.                   are for your personal use. You may not copy this  soft-
  76.                   ware,  or  manual,  in any form  whatsoever  for  usage 
  77.                   outside of your personal use. This includes, but is not 
  78.                   limited  to, duplication of the disk, the files on  the 
  79.                   disk or the manual, by manual or electronic means.
  80.         
  81.         
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.                                             2
  131.                                             
  132.                                      TABLE OF CONTENTS
  133.                                      -----------------
  134.         
  135.                   
  136.                    Subject                                     Page
  137.                    -----------------------------------------------------
  138.         
  139.                    GENERAL DESCRIPTION ......................    4
  140.                      Introduction ...........................    4
  141.                      The software ...........................    4
  142.                                                              
  143.                    THE SOFTWARE IN DETAIL ...................    5
  144.                      Function Return Codes ..................    5
  145.                      Functions and Procedures ...............    6
  146.                      Usage Pointers .........................    9
  147.                                                              
  148.                    INDEX ....................................   10
  149.         
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.                                             3
  197.  
  198.                                     GENERAL DESCRIPTION
  199.                                     -------------------
  200.  
  201.                   Introduction
  202.                   ------------
  203.  
  204.                      Welcome to Version 1.0 of Software Technology Inter-
  205.                   nationals' Virtual Memory Management System. This group
  206.                   of functions will enable your Turbo Pascal Version  5.0
  207.                   access  to  up to 40 megabytes of data.  The  functions
  208.                   were  written to be flexible, as fast as possible,  and
  209.                   as  easy  to use as possible. We hope they live  up  to
  210.                   your  expectations.  Please feel free to  write  to  us
  211.                   anytime  with  bug reports or  suggestions  for  future
  212.                   versions.  If  you  are a registered  user,  this  will
  213.                   entitle you to a free upgrade.
  214.                      Remember  that  this  software  is  copyrighted,  so
  215.                   please don't copy and distribute it, this is a  federal
  216.                   offense.
  217.  
  218.                   The Software
  219.                   ------------
  220.  
  221.                      This is a group of 10 functions and procedures which
  222.                   will give your programs access to up to 40 megabytes of
  223.                   data.  To be exact, the system supports up to  10  swap
  224.                   files with up to 65535 pages of up to 65535 bytes each.
  225.                   If  you add this up, you get a total of  42,948,362,250
  226.                   bytes you may access. Each of those swap files may have
  227.                   up  to 4096 pages resident in conventional  memory, de-
  228.                   pending on the page size.
  229.  
  230.                      There  is no restriction on the type of  data  these
  231.                   functions  may handle, so any valid Turbo  Pascal  type
  232.                   may be stored and accessed through these functions.
  233.  
  234.                      The  system  takes advantage of the fact  that  most
  235.                   programs  spend a lot of time in each area  of  memory,
  236.                   and generally don't access all elements in order.  This
  237.                   is  called  locality, and is well  known  in  Operating
  238.                   System circles. The program uses the LRU (Least Recent-
  239.                   ly  Used)  algorithm to try to keep cache misses  to  a
  240.                   minimum.
  241.  
  242.                      Access  to  a page that is resident on disk,  is  of
  243.                   course a lot slower than directly accessing memory. You
  244.                   will find however, that with a good hard disk, or a RAM
  245.                   disk,  the  difference will not be so  great.  However,
  246.                   with floppy disks, things will be a lot slower.
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262.                                             4
  263.  
  264.                                   THE SOFTWARE IN DETAIL
  265.                                   ----------------------
  266.  
  267.  
  268.                   The Function and Procedure Return Codes
  269.                   ----------------------------------------
  270.  
  271.                      All  of the functions use the following error  codes
  272.                   for return values.
  273.  
  274.                   ALL_OK                = 0;
  275.  
  276.                      This is used to signify that the function managed to
  277.                   complete with no errors.
  278.  
  279.                   BAD_VM_ID             = -1;
  280.  
  281.                      This  is used to signify that the ID  variable  that
  282.                   you  passed to the function is invalid. This is due  to
  283.                   either the number being to large or too small, the swap
  284.                   file  being already used, or the swap file  not  having
  285.                   being initialised (opened).
  286.  
  287.                   PAGE_SIZE_TOO_BIG     = -2;
  288.  
  289.                      This  is  used to show that the page  size  is  over
  290.                   65535  bytes.  You should reduce the size of  the  data
  291.                   structure you are trying to allocate.
  292.  
  293.                   PAGE_SIZE_TOO_SMALL   = -3;
  294.  
  295.                      This  is  used  to show that the page  size  is  too
  296.                   small.  In  fact, this is never  returned  because  all
  297.                   pages less that 128 bytes are rounded up.
  298.  
  299.                   CACHE_SIZE_TOO_BIG    = -4;
  300.  
  301.                      This is used to show that the cache size is  greater
  302.                   than 4096 pages. You should reduce the size.
  303.  
  304.                   CACHE_SIZE_TOO_SMALL  = -5;
  305.  
  306.                      This  is used to indicate that the cache size is too
  307.                   small,  or less than one page. You should increase  the
  308.                   size to 1 or more.
  309.  
  310.                   FILE_CREATE_ERROR     = -6;
  311.  
  312.                      This  is used to indicate that the system could  not
  313.                   create,  or  open the file specified.  Check  the  file
  314.                   names, or space on the disk.
  315.  
  316.  
  317.  
  318.  
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.  
  328.                                             5
  329.  
  330.                   OUT_OF_MEMORY         = -7;
  331.  
  332.                      This is used to show that the system has run out  of
  333.                   conventional memory. This is due to the caches being to
  334.                   large,  or the page size being too large. Check all  of
  335.                   these parameters.
  336.  
  337.                   BAD_PAGE_NUMBER       = -8;
  338.  
  339.                      This is used to indicate that the page number handed
  340.                   to the system is either too big, or too small. That is,
  341.                   this page has not been allocated.
  342.  
  343.  
  344.                   The Functions And Procedures
  345.                   ----------------------------
  346.  
  347.  
  348.                   function STI_VM_Open(ID        : byte;
  349.                                        Swap      : string;
  350.                                        Page_Size,
  351.                                        Cache     : word) : shortint;
  352.  
  353.                       This  is the function you can use to create  a  new
  354.                   swap  file. The ID variable is the number of  the  swap
  355.                   file.  The SWAP variable is the path and file name  for
  356.                   the  swap  file. The PAGE_SIZE is how large  the  pages
  357.                   are, and the CACHE is how many pages to cache in  memo-
  358.                   ry.  The  return codes are exactly the  same  as  those
  359.                   above.  The only important point here is that the  page
  360.                   size  is always rounded up to a multiple of 128, so  it
  361.                   is better to try to make your data structures a  multi-
  362.                   ple of 128 bytes, otherwise you will waste memory.
  363.  
  364.  
  365.                   function STI_VM_ReOpen(ID   : byte;
  366.                                          Swap : string) : shortint;
  367.  
  368.                       This function is used to open a previously  created
  369.                   swap  file. The ID and SWAP variables are  exactly  the
  370.                   same as for the function above. The only difference  is
  371.                   that all the other parameters are read in from the swap
  372.                   file.  This gives you a very powerful ability  to  swap
  373.                   data  between applications without having to  know  all
  374.                   the  details  of  the data structure.  With  this,  you
  375.                   should  be able to transfer data or RUN TIME  LIBRARIES
  376.                   between programs. You can do this by copying a function
  377.                   or program without a header to the swap file, and  then
  378.                   calling the first byte of the page.
  379.  
  380.  
  381.  
  382.  
  383.  
  384.  
  385.  
  386.  
  387.  
  388.  
  389.  
  390.  
  391.  
  392.  
  393.  
  394.                                             6
  395.  
  396.                   function  STI_VM_Flush_Cache(ID : Byte) : shortint;
  397.  
  398.                      This function is used to flush the cache  associated
  399.                   with  the ID variable. The ID variable must be a  valid
  400.                   (opened)  ID or the function will return an error.  The
  401.                   error codes are as above.
  402.  
  403.                   function STI_VM_Allocate(ID : byte;
  404.                                            Var Point) : longint;
  405.  
  406.                       This is the function you should use to  allocate  a
  407.                   virtual page. The ID variable must be a valid  (opened)
  408.                   ID. The POINT variable should be a pointer to ANY valid
  409.                   Turbo Pascal type. The pointer will be set to point  to
  410.                   an area of memory that can be used in the regular  way.
  411.                   The  return  codes  of this function are  the  same  as
  412.                   above, or it will return the positive PAGE NUMBER.
  413.  
  414.                   function STI_VM_Demand(ID : byte;
  415.                                          Var  Point;
  416.                                          PageNo : word) : shortint;
  417.  
  418.                      This  function is used to demand a page, or to  make
  419.                   sure a page is in memory. It is wise to do this  before
  420.                   every  memory  access, unless the cache size,  and  the
  421.                   number  of pages is the same(a rare case). The ID is  a
  422.                   valid  (opened) ID variable, the POINT is a pointer  to
  423.                   ANY  valid  Turbo Pascal type, and the  PAGENO  is  the
  424.                   previously allocated page number. Functions returns are
  425.                   as above.
  426.  
  427.  
  428.                   function STI_VM_Rollback(ID : byte;
  429.                                            Var Point;
  430.                                            PageNo : word) : shortint;
  431.  
  432.                      This function is used to erase changes you have made
  433.                   to  a cached page. It will read in the page  from  disk
  434.                   and reassign the pointer, if necessary. This will  only
  435.                   work  if  the page hasn't been written  out  after  the
  436.                   changes,  and the page was written out recently  before
  437.                   the changes. The ID is any valid ID variable, the POINT
  438.                   is  a pointer to any valid Turbo Pascal type,  and  the
  439.                   PAGENo  is any valid page number. Return codes  are  as
  440.                   above.
  441.  
  442.  
  443.  
  444.  
  445.  
  446.  
  447.  
  448.  
  449.  
  450.  
  451.  
  452.  
  453.  
  454.  
  455.  
  456.  
  457.  
  458.  
  459.  
  460.                                             7
  461.  
  462.                   function STI_VM_Close(ID : byte;
  463.                                         EraseFile : boolean) : shortint;
  464.  
  465.                       This  function is used to close a  swap  file,  and
  466.                   erase  the  contents of memory. First  it  flushes  the
  467.                   cache,  and then it frees up the memory. The ID is  any
  468.                   valid ID variable, and the ERASEFILE is a flag  telling
  469.                   the  system  whether it should erase the file  or  not.
  470.                   Return codes are as above.
  471.  
  472.                   function  STI_VM_Hit_Rate : real;
  473.  
  474.                      This function returns the percentage ratio of  cache
  475.                   hits  to misses. You must call STI_VM_Log_Cache  before
  476.                   you use this, otherwise the results will be false. This
  477.                   is useful for tuning thee system.
  478.  
  479.                   procedure STI_VM_Init;
  480.  
  481.                      This procedure initialises the system. It is a  good
  482.                   idea  to always call this, but is not  strictly  neces-
  483.                   sary.
  484.  
  485.                   procedure STI_VM_Log_Cache(B : boolean);
  486.  
  487.                      This  procedure sets an internal flag,  telling  the
  488.                   system to log the performance of the caches. note  that
  489.                   this  is  the performance of ALL the caches,  not  just
  490.                   one.  So if you are fine tuning a system, it is a  good
  491.                   idea to do so ONE SWAP FILE AT A TIME.
  492.  
  493.  
  494.  
  495.  
  496.  
  497.  
  498.  
  499.  
  500.  
  501.  
  502.  
  503.  
  504.  
  505.  
  506.  
  507.  
  508.  
  509.  
  510.  
  511.  
  512.  
  513.  
  514.  
  515.  
  516.  
  517.  
  518.  
  519.  
  520.  
  521.  
  522.  
  523.  
  524.  
  525.  
  526.                                             8
  527.  
  528.                                       USAGE POINTERS
  529.                                       --------------
  530.  
  531.                      If you look at the demostration program, you can see
  532.                   an  example  of how each function is used.  In  general
  533.                   though, you don't have to follow this example. In  real
  534.                   use, basically you have to do the following.
  535.  
  536.                     1) Initialise the system using STI_VM_Init,
  537.                        but this is not vitally important.
  538.                     2) Open a swap file using STI_VM_Open. Using sizeof()
  539.                        for specifiying page size is recommended.
  540.                     3) Allocate the pages you need using STI_VM_Allocate.
  541.                     4) Access and modify the data. To do this it is
  542.                        recommended that you use STI_VM_Demand before
  543.                        accessing every data item.
  544.                     5) Close the swap file using STI_VM_Close.
  545.  
  546.                      You  should  be aware that having a big  cache  will
  547.                   generally result in better performance, but not always.
  548.                   The  most  important  thing here is  how  your  program
  549.                   accesses the data. If it accesses the data  sequential-
  550.                   ly,  forward and then backward, a large cache  will  be
  551.                   very effective, otherwise, try to minimize the size  of
  552.                   the   cache.   If   you   use   the   STI_VM_Log,   and
  553.                   STI_VM_Hit_Rate functions, you will be able to see  the
  554.                   point at which performace is best.
  555.  
  556.  
  557.  
  558.  
  559.  
  560.  
  561.  
  562.  
  563.  
  564.  
  565.  
  566.  
  567.  
  568.  
  569.  
  570.  
  571.  
  572.  
  573.  
  574.  
  575.  
  576.  
  577.  
  578.  
  579.  
  580.  
  581.  
  582.  
  583.  
  584.  
  585.  
  586.  
  587.  
  588.  
  589.  
  590.  
  591.  
  592.                                             9
  593.  
  594.                                            INDEX
  595.                                            -----
  596.  
  597.                     Topic                                     Page Number
  598.                   -------------------------------------------------------
  599.  
  600.                   Algorithm ................................     4
  601.                   ALL_OK ...................................     5
  602.  
  603.                   BAD_PAGE_NUMBER ..........................     6
  604.                   BAD_VM_ID ................................     5
  605.  
  606.                   Cache Performance ........................     8
  607.                   Cache Size ...............................     6
  608.                   CACHE_SIZE_TOO_BIG .......................     5
  609.                   CACHE_SIZE_TOO_SMALL .....................     5
  610.                   Contents .................................     3
  611.                   Copying ..................................     2
  612.                   Copyright ................................     2
  613.  
  614.                   Data .....................................     7
  615.                   Data Changes .............................     7
  616.                   Data Types ...............................     4, 7
  617.                   Description ..............................     4
  618.                   Descriptions .............................     6
  619.  
  620.                   EraseFile ................................     8
  621.                   Exchanging Data ..........................     6
  622.  
  623.                   FILE_CREATE_ERROR ........................     5
  624.                   Functions ................................     6
  625.  
  626.                   ID .......................................     6
  627.                   Initialisation ...........................     8
  628.  
  629.                   Number of Pages ..........................     4
  630.  
  631.                   OUT_OF_MEMORY ............................     6
  632.  
  633.                   Page Size ................................     6
  634.                   Pages ....................................     7
  635.                   Pages Sizes ..............................     4
  636.                   PAGE_SIZE_TOO_BIG ........................     5
  637.                   PAGE_SIZE_TOO_SMALL ......................     5
  638.                   Pointers .................................     7
  639.                   Procedures ...............................     6
  640.  
  641.                   Return Codes .............................     5
  642.  
  643.                   Software .................................     4
  644.                   STI_VM_Allocate ..........................     7
  645.                   STI_VM_Close .............................     8
  646.                   STI_VM_Demand ............................     7
  647.                   STI_VM_Flush_Cache .......................     7
  648.                   STI_VM_Hit_Rate ..........................     8
  649.  
  650.  
  651.  
  652.  
  653.  
  654.  
  655.  
  656.  
  657.  
  658.                                             10
  659.  
  660.                   STI_VM_Init ..............................     8
  661.                   STI_VM_Log_Cache .........................     8
  662.                   STI_VM_Open ..............................     6
  663.                   STI_VM_ReOpen ............................     6
  664.                   STI_VM_Rollback ..........................     7
  665.                   Swap File Size ...........................     4
  666.                   Swap Files ...............................     8
  667.         
  668.                   Usage ....................................     9
  669.                   Usage Steps ..............................     9
  670.                   Users ....................................     2, 4
  671.         
  672.                   Virtual Memory ...........................     4
  673.         
  674.         
  675.  
  676.  
  677.  
  678.  
  679.  
  680.  
  681.  
  682.  
  683.  
  684.  
  685.  
  686.  
  687.  
  688.  
  689.  
  690.  
  691.  
  692.  
  693.  
  694.  
  695.  
  696.  
  697.  
  698.  
  699.  
  700.  
  701.  
  702.  
  703.  
  704.  
  705.  
  706.  
  707.  
  708.  
  709.  
  710.  
  711.  
  712.  
  713.  
  714.  
  715.  
  716.  
  717.  
  718.  
  719.  
  720.  
  721.  
  722.  
  723.  
  724.                                             11
  725.  
  726.  
  727.