home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / library / dos / nicol / sti_vm / stivpdem.pas < prev   
Encoding:
Pascal/Delphi Source File  |  1979-12-31  |  3.1 KB  |  81 lines

  1. program STIVPDEMO;                          { demonstration of VP           }
  2.  
  3. uses STI_VPTR,                              { virtual pointer unit          }
  4.      CRT;                                   { standard CRT unit             }
  5.  
  6. Type
  7.   DataRec = record                          { example data record           }
  8.               Data  : string[50];           { the data                      }
  9.               Page  : word;                 { the page number               }
  10.             end;
  11.   DataPtr = ^DataRec;                       { pointer to it                 }
  12.  
  13. Var
  14.   TestData : array[1..NUMPAGES] of STI_VPointer; { array of virtual pointer }
  15.   Loop     : word;                          { general loop variable         }
  16.  
  17. {---------------------------------------------------------------------------}
  18.  
  19. procedure Explain;
  20.  
  21. Var
  22.   Dummy : char;
  23.  
  24. begin
  25.   writeln('                               STIVPDEM.PAS');
  26.   writeln;
  27.   writeln('              This is a demonstration of STI_PTR, a unit that gives');
  28.   writeln('              the ability to use Virtual Memory Pointers.');
  29.   writeln;
  30.   writeln('              Press any key to continue.....');
  31.   repeat until keypressed;
  32.   Dummy := ReadKey;
  33. end;
  34.  
  35. {---------------------------------------------------------------------------}
  36.  
  37. begin
  38.   ClrScr;                                   { wipe the screen               }
  39.   Explain;
  40.   ClrScr;
  41.   WriteLn('Available Memory = ',MaxAvail);
  42.   Writeln('Initialising the VP system');
  43.   STI_VPInitialise('STI_VPTR.SWP',          { swap file name                }
  44.                     NUMPAGES,               { number of pages (GLOBAL VAL)  }
  45.                     sizeof(DataRec));       { size of a page                }
  46.   Writeln('Allocating the memory');
  47.   for Loop := 1 to NUMPAGES do              { loop to NUMPAGES              }
  48.     begin
  49.       STI_VPGetMem(TestData[Loop]);         { get virtual memory            }
  50.     end;
  51.   Writeln('Assigning data to the memory');
  52.   for Loop := 1 to NUMPAGES do              { loop & assign data            }
  53.     begin                                   { take note of type cast        }
  54.       DataPtr(TestData[Loop])^.Data := 'Software Technology International';
  55.       DataPtr(TestData[Loop])^.Page  := Loop;
  56.     end;
  57.   Writeln('Reading the memory');
  58.   for Loop := 1 to NUMPAGES do              { loop and print data           }
  59.     begin                                   { again type cast is needed     }
  60.       GotoXY(1,6);
  61.       WriteLn(DataPtr(TestData[Loop])^.Data,'/',
  62.               DataPtr(TestData[Loop])^.Page,'/',Loop);
  63.     end;
  64.   Writeln('Freeing the memory');
  65.   for Loop := 1 to NUMPAGES do
  66.     begin
  67.       STI_VPFreeMem(Addr(TestData[Loop]));  { free memory                   }
  68.     end;                                    { MUST USE ADDR HERE OR ELSE    }
  69.                                             { THE MEMORY IS NOT FREED       }
  70.   Writeln('Closing Down the sysytem');
  71.   STI_VPClose;                              { close and erase swap file     }
  72.   Writeln('Available Memory = ',MaxAvail);
  73. end.
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.