-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfifo.cpp
More file actions
46 lines (39 loc) · 1.03 KB
/
fifo.cpp
File metadata and controls
46 lines (39 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include "fifo.h"
namespace coen383
{
//CONSTRUCTOR
fifo::fifo()
{
pageRequest = 0;
numElements = 0;
pageNumber = 0;
numCount = 0;
//*used for debugging*//
//myfile.open ("output");
}
void fifo::pageReplaceAlgo()
{
setItr = set.find(pageRequest);
if(setItr == set.end())
{
//page does not already exist in the cache
std::cout<<"Page number "<<pageRequest<<" caused a page fault."<<std::endl;
// myfile<<"Page number "<<pageRequest<<" caused a page fault.\n";
if(llist.size() >= tableSize)
{
set.erase(llist.back());
llist.pop_back();
}
llist.push_front(pageRequest);
set.insert(pageRequest);
numCount++;
}
else
std::cerr<<"Page number "<<pageRequest<<" caused a page hit."<<std::endl;
//*used for debugging*//
// std::cerr<<"llist: ";
// for (std::list<int>::const_iterator it = llist.begin(); it != llist.end(); ++it)
// std::cerr<<*it<<" ";
// std::cerr<<std::endl;
}
}