// vm.cpp Dave Reed 11/10/03 // // Virtual Memory Simulator: currently uses FCFS page replacement ////////////////////////////////////////////////////////////////// #include #include "PageTable.h" using namespace std; int main() { int logSize; cout << "Enter number of pages in logical memory: " << endl; cin >> logSize; int physSize; cout << "Enter number of frames in physical memory: " << endl; cin >> physSize; PageTable PT(logSize, physSize); // CREATE THE PAGE TABLE int pageNum; while (cin >> pageNum) { // REPEAT UNTIL END OF INPUT if (PT.AccessPage(pageNum)) { // ATTEMPT PAGE ACCESS, cout << pageNum << ": found at frame " // IF IN MEMORY, DONE << PT.LocatePage(pageNum) << endl; } else if (PT.FreeFramesRemaining()) { // ELSE IF A FRAME IS FREE PT.StorePage(pageNum); // STORE THE PAGE cout << pageNum << ": PAGE FAULT -- added at frame " << PT.LocatePage(pageNum) << endl; } else { // ELSE SELECT A PAGE AND int selected = PT.SelectSwapPage(); // SWAP WITH THE NEW PAGE PT.ReplacePage(pageNum, selected); cout << pageNum << ": PAGE FAULT -- replaces page " << selected << " at frame " << PT.LocatePage(pageNum) << endl; } } return 0; }