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

  1. program STIVMDEMO;                          {demonstration program for STIs }
  2.                                             {virtual memory management unit }
  3. Uses Dos,Crt,STI_VM;                        {STI_VM is the unit             }
  4.  
  5. Type
  6.    DataRec = record                         {test data type                 }
  7.                Name : string;
  8.                Age  : word;
  9.              end;
  10.    DataPtr = ^DataRec;                      {pointer to it                  }
  11.  
  12.    StrPtr  = ^String;                       {pointer to a string            }
  13.  
  14. Var
  15.   Data1 : DataPtr;                          {data pointer 1                 }
  16.   Data2 : StrPtr;                           {data pointer 2                 }
  17.   SH,SM,SS,SS1,                             {timing variables               }
  18.   FH,FM,FS,FS1 : word;
  19.   Dum1,
  20.   Dum2,
  21.   Loop  : word;                             {dummy variables                }
  22.   Test  : shortint;                         {dummy to hold return codes     }
  23.  
  24. {---------------------------------------------------------------------------}
  25.  
  26. procedure Explain;
  27.  
  28. Var
  29.   Dummy : char;
  30.  
  31. begin
  32.   writeln('                               STIVMDEM.PAS');
  33.   writeln;
  34.   writeln('              This is a demonstration of STI_VM, a unit that gives');
  35.   writeln('              the ability to use Virtual Memory, and to exchange  ');
  36.   writeln('              Data.');
  37.   writeln;
  38.   writeln('              Press any key to continue.....');
  39.   repeat until keypressed;
  40.   Dummy := ReadKey;
  41. end;
  42.  
  43. {---------------------------------------------------------------------------}
  44.  
  45. begin
  46.   ClrScr;                                   {clear the screen               }
  47.   Explain;
  48.   ClrScr;
  49.   Randomize;                                {randomize the random fucntion  }
  50.   STI_VM_Init;                              {initialise the VM system       }
  51.   GetTime(SH,SM,SS,SS1);                    {get the time & open swap files }
  52.   writeln('Available Memory = ',MaxAvail,' bytes');
  53.   writeln('Opening swap file 1 = ',STI_VM_Open(1,'TEST1.$$$',sizeof(DataRec),100));
  54.   writeln('Opening swap file 2 = ',STI_VM_Open(2,'TEST2.$$$',sizeof(String),100));
  55.   writeln('Available Memory = ',MaxAvail,' bytes');
  56.   for loop := 1 to 200 do                   {loop and allocate the data     }
  57.     begin
  58.       gotoxy(1,4);
  59.       writeln('Allocating #1 page number ',loop,' = ',STI_VM_Allocate(1,Data1));
  60.       gotoxy(1,5);
  61.       writeln('Allocating #2 page number ',loop,' = ',STI_VM_Allocate(2,Data2));
  62.       Data1^.Name := 'George James Smith';
  63.       Data1^.Age  := Loop;
  64.       str(loop,Data2^);
  65.       Data2^ := 'This is Page Number ' + Data2^;
  66.     end;
  67.   writeln('Available Memory = ',MaxAvail,' bytes');
  68.   test := STI_VM_Flush_Cache(1);            {flush the caches, not really   }
  69.   test := STI_VM_Flush_Cache(2);            {needed                         }
  70.   STI_VM_Log_Cache(True);                   {start logging cache performance}
  71.   for loop := 1 to 200 do                   {then loop & demand random pages}
  72.     begin
  73.       Dum1 := random(199)+1;
  74.       gotoxy(1,7);
  75.       writeln('Demanding #1 page number ',Dum1,' = ',STI_VM_Demand(1,Data1,Dum1),'    ');
  76.       writeln('Page ',loop,' Name = ',Data1^.Name,' Age = ',Data1^.Age,'    ');
  77.       Dum1 := random(199)+1;
  78.       gotoxy(1,9);
  79.       writeln('Demanding #2 page number ',Dum1,' = ',STI_VM_Demand(2,Data2,Dum1),'    ');
  80.       writeln('Page ',loop,' Data = ',Data2^,'    ');
  81.     end;
  82.   writeln('Cache hit rate  = ',STI_VM_Hit_Rate:2:2,'%');
  83.  
  84.   {cache performance on a loop of 10000 turned out to be linear in the case }
  85.   {of random data access. The values were as follows                        }
  86.   {                                                                         }
  87.   {   cache size = 100  data items = 200   hit rate = 50.4%                 }
  88.   {   cache size = 50   data items = 200   hit rate = 25.2%                 }
  89.   {                                                                         }
  90.   {this is actually quite good, because the access was RANDOM. programs     }
  91.   {do not exhibit this kind of access, so performance may be better         }
  92.  
  93.   STI_VM_Log_Cache(FALSE);                  {stop logging and close swaps   }
  94.   writeln('Closing #1 = ',STI_VM_Close(1,FALSE));
  95.   writeln('Closing #2 = ',STI_VM_Close(2,FALSE));
  96.   writeln('Reopening #1 = ',STI_VM_ReOpen(1,'TEST1.$$$'));  {reopen files   }
  97.   writeln('Reopening #2 = ',STI_VM_ReOpen(2,'TEST2.$$$'));
  98.   STI_VM_Log_Cache(True);
  99.   for loop := 1 to 200 do                   {loop & verify data             }
  100.     begin
  101.       gotoxy(1,16);
  102.       writeln('Demanding #1 page number ',loop,' = ',STI_VM_Demand(1,Data1,loop),'    ');
  103.       writeln('Page ',loop,' Name = ',Data1^.Name,' Age = ',Data1^.Age,'    ');
  104.       gotoxy(1,18);
  105.       writeln('Demanding #2 page number ',loop,' = ',STI_VM_Demand(2,Data2,loop),'    ');
  106.       writeln('Page ',loop,' Data = ',Data2^,'    ');
  107.     end;
  108.   writeln('Cache hit rate  = ',STI_VM_Hit_Rate:2:2,'%');
  109.   STI_VM_Log_Cache(FALSE);
  110.   writeln('Closing #1 = ',STI_VM_Close(1,TRUE));
  111.   writeln('Closing #2 = ',STI_VM_Close(2,TRUE));
  112.   GetTime(FH,FM,FS,FS1);                    {get the finishing time         }
  113.   writeln('Finished demonstration .....');
  114.   write('Start = ',SH,':',SM,':',SS,':',SS1);
  115.   writeln('   End = ',FH,':',FM,':',FS,':',FS1);
  116.   writeln('Available Memory = ',MaxAvail,' bytes');
  117. end.
  118.  
  119.