Question: Part 1 : FIFO Page Replacement ( 3 0 points ) Now that we have a means of generating addresses and getting their corresponding page
Part : FIFO Page Replacement 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::findfifoqueue.begin fifoqueue.end pagenumber;
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 fifoqueue.end
std::cout "PAGE FAULT! Page not found. Adding missing page...
;
Push the missing page at the front of the queue.
fifoqueue.pushfrontpagenumber;
If the length of the queue exceeds the value assigned
to numpageframes, pop the page at the back.
if fifoqueue.size numpageframes
fifoqueue.popback;
return ;
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.
FIFO queue
And FIFO page fault count
std: :list fifoqueue;
int fifopagefaultcount ;
for int i ; i ; 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 fifoqueue.end
std::cout "PAGE FAULT! Page not found. Adding missing page...
;
fifopagefaultcount;
Push the missing page at the front of the queue.
fifoqueue.pushfrontpagenumber;
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 numpageframes, pop the page at the back.
if fifoqueue.size numpageframes
fifoqueue.popback;
Print out page fault counts
std::cout "FIFO page faults:
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
