home *** CD-ROM | disk | FTP | other *** search
- program STIVMDEMO; {demonstration program for STIs }
- {virtual memory management unit }
- Uses Dos,Crt,STI_VM; {STI_VM is the unit }
-
- Type
- DataRec = record {test data type }
- Name : string;
- Age : word;
- end;
- DataPtr = ^DataRec; {pointer to it }
-
- StrPtr = ^String; {pointer to a string }
-
- Var
- Data1 : DataPtr; {data pointer 1 }
- Data2 : StrPtr; {data pointer 2 }
- SH,SM,SS,SS1, {timing variables }
- FH,FM,FS,FS1 : word;
- Dum1,
- Dum2,
- Loop : word; {dummy variables }
- Test : shortint; {dummy to hold return codes }
-
- {---------------------------------------------------------------------------}
-
- procedure Explain;
-
- Var
- Dummy : char;
-
- begin
- writeln(' STIVMDEM.PAS');
- writeln;
- writeln(' This is a demonstration of STI_VM, a unit that gives');
- writeln(' the ability to use Virtual Memory, and to exchange ');
- writeln(' Data.');
- writeln;
- writeln(' Press any key to continue.....');
- repeat until keypressed;
- Dummy := ReadKey;
- end;
-
- {---------------------------------------------------------------------------}
-
- begin
- ClrScr; {clear the screen }
- Explain;
- ClrScr;
- Randomize; {randomize the random fucntion }
- STI_VM_Init; {initialise the VM system }
- GetTime(SH,SM,SS,SS1); {get the time & open swap files }
- writeln('Available Memory = ',MaxAvail,' bytes');
- writeln('Opening swap file 1 = ',STI_VM_Open(1,'TEST1.$$$',sizeof(DataRec),100));
- writeln('Opening swap file 2 = ',STI_VM_Open(2,'TEST2.$$$',sizeof(String),100));
- writeln('Available Memory = ',MaxAvail,' bytes');
- for loop := 1 to 200 do {loop and allocate the data }
- begin
- gotoxy(1,4);
- writeln('Allocating #1 page number ',loop,' = ',STI_VM_Allocate(1,Data1));
- gotoxy(1,5);
- writeln('Allocating #2 page number ',loop,' = ',STI_VM_Allocate(2,Data2));
- Data1^.Name := 'George James Smith';
- Data1^.Age := Loop;
- str(loop,Data2^);
- Data2^ := 'This is Page Number ' + Data2^;
- end;
- writeln('Available Memory = ',MaxAvail,' bytes');
- test := STI_VM_Flush_Cache(1); {flush the caches, not really }
- test := STI_VM_Flush_Cache(2); {needed }
- STI_VM_Log_Cache(True); {start logging cache performance}
- for loop := 1 to 200 do {then loop & demand random pages}
- begin
- Dum1 := random(199)+1;
- gotoxy(1,7);
- writeln('Demanding #1 page number ',Dum1,' = ',STI_VM_Demand(1,Data1,Dum1),' ');
- writeln('Page ',loop,' Name = ',Data1^.Name,' Age = ',Data1^.Age,' ');
- Dum1 := random(199)+1;
- gotoxy(1,9);
- writeln('Demanding #2 page number ',Dum1,' = ',STI_VM_Demand(2,Data2,Dum1),' ');
- writeln('Page ',loop,' Data = ',Data2^,' ');
- end;
- writeln('Cache hit rate = ',STI_VM_Hit_Rate:2:2,'%');
-
- {cache performance on a loop of 10000 turned out to be linear in the case }
- {of random data access. The values were as follows }
- { }
- { cache size = 100 data items = 200 hit rate = 50.4% }
- { cache size = 50 data items = 200 hit rate = 25.2% }
- { }
- {this is actually quite good, because the access was RANDOM. programs }
- {do not exhibit this kind of access, so performance may be better }
-
- STI_VM_Log_Cache(FALSE); {stop logging and close swaps }
- writeln('Closing #1 = ',STI_VM_Close(1,FALSE));
- writeln('Closing #2 = ',STI_VM_Close(2,FALSE));
- writeln('Reopening #1 = ',STI_VM_ReOpen(1,'TEST1.$$$')); {reopen files }
- writeln('Reopening #2 = ',STI_VM_ReOpen(2,'TEST2.$$$'));
- STI_VM_Log_Cache(True);
- for loop := 1 to 200 do {loop & verify data }
- begin
- gotoxy(1,16);
- writeln('Demanding #1 page number ',loop,' = ',STI_VM_Demand(1,Data1,loop),' ');
- writeln('Page ',loop,' Name = ',Data1^.Name,' Age = ',Data1^.Age,' ');
- gotoxy(1,18);
- writeln('Demanding #2 page number ',loop,' = ',STI_VM_Demand(2,Data2,loop),' ');
- writeln('Page ',loop,' Data = ',Data2^,' ');
- end;
- writeln('Cache hit rate = ',STI_VM_Hit_Rate:2:2,'%');
- STI_VM_Log_Cache(FALSE);
- writeln('Closing #1 = ',STI_VM_Close(1,TRUE));
- writeln('Closing #2 = ',STI_VM_Close(2,TRUE));
- GetTime(FH,FM,FS,FS1); {get the finishing time }
- writeln('Finished demonstration .....');
- write('Start = ',SH,':',SM,':',SS,':',SS1);
- writeln(' End = ',FH,':',FM,':',FS,':',FS1);
- writeln('Available Memory = ',MaxAvail,' bytes');
- end.
-