Question: Part 1 : FIFO Page Replacement ( 3 0 points ) Now that we have a means of generating addresses and getting their corresponding page

Part 1: FIFO Page Replacement (30 points)
Now that we have a means of "generating" addresses and getting their corresponding page numbers, we can implement our first page replacement algorithm: FIFO page replacement.
Begin by adding the following code after the line that prints the page number.
```
// Check if the page is in the FIFO queue already by iterating
// through the FIFO queue.
// This iterator will either point to where the page is in the queue
// OR point at the end, indicating the page wasn't found.
auto iter = std::find(fifo_queue.begin(), fifo_queue.end(), page_number);
// If it was found, then iter won't be pointing at the end. Yay!
// If not, push it at the front of the queue.
// If there's no room, pop a page and then push.
if (iter == fifo_queue.end()){
std::cout "PAGE FAULT! Page not found. Adding missing page...
";
// Push the missing page at the front of the queue.
fifo_queue.push_front(page_number);
// If the length of the queue exceeds the value assigned
// to num_page_frames, pop the page at the back.
if (fifo_queue.size()> num_page_frames){
fifo_queue.pop_back();
}
}
}
return 0;
}
```
Note: the "auto" keyword is used to deduce the datatype of a variable. If your compiler does not support this keyword, replace it with "std::list::iterator". Add a new variable to track the number of page faults that occurred using FIFO.
14// FIFO queue
15// And FIFO page fault count
std: :list fifo_queue;
int fifo_page_fault_count =0;
for (int i =0; i 20; i++)\{
Then, after the line that prints out "PAGE FAULT!", add a line of code that increments the page fault count.
```
// If it was found, then iter won't be pointing at the end. Yay!
// If not, push it at the front of the queue.
// If there's no room, pop a page and then push.
if (iter == fifo_queue.end()){
std::cout "PAGE FAULT! Page not found. Adding missing page...
";
fifo_page_fault_count++;
// Push the missing page at the front of the queue.
fifo_queue.push_front(page_number);
```
Finally, after the for loop, add a line of code that prints out the number of FIFO page faults.
```
// If the length of the queue exceeds the value assigned
// to num_page_frames, pop the page at the back.
if (fifo_queue.size()> num_page_frames){
fifo_queue.pop_back();
}
}
}
// Print out page fault counts
std::cout "FIFO page faults: "
Part 1 : FIFO Page Replacement ( 3 0 points ) Now

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!