-
Notifications
You must be signed in to change notification settings - Fork 0
/
FirstInFirstOut.cpp
43 lines (41 loc) · 1.19 KB
/
FirstInFirstOut.cpp
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
//This code is contributed by Sourajita Dewasi
#include<iostream>
using namespace std;
int main()
{ cout<<"\n First In First Out Simulation";
int reference_string[12]={5,1,2,3,5,1,4,5,1,2,3,4};
int page_faults = 0;
int m, n, s, pages=12, frames=4;
int temp[frames];
for(m = 0; m < frames; m++)
{
temp[m] = -1;
}
for(m = 0; m < pages; m++)
{
s = 0;
for(n = 0; n < frames; n++)
{
if(reference_string[m] == temp[n])
{
s++;
page_faults--;
}
}
page_faults++;
if((page_faults <= frames) && (s == 0))
{ temp[m] = reference_string[m]; }
else if(s == 0)
{
temp[(page_faults - 1) % frames] = reference_string[m];
}
cout<<"\n";
for(n = 0; n < frames; n++)
{
cout<<"\t\t"<< temp[n];
}
}
cout<<"\n Total Number of Page Faults "<<page_faults;
cout<<"\n Total number of Page Hits "<<pages-page_faults;
return 0;
}