Question: Using the Page Replacement simulation from the previous assignment, implement ONE of the following algorithms: 1) Optimal 2) Second Chance Implement only ONE of the

Using the Page Replacement simulation from the previous assignment, implement ONE of the following algorithms:

1) Optimal 2) Second Chance

Implement only ONE of the above algorithms by editing the MemoryManager class. You will not have to modify any other class in the simulation.

Here are some simulation methods you can call as part of your implementation, if necessary:

sim.getAccesses() - returns an int array containing the sequence of page references.

sim.getCurrentAccess() - returns an index for the array returned by the method above; the index identifies the current page reference.

sim.getFrameTable() - returns an int array containing the page numbers of the resident pages.

sim.getNumberFrames() - returns the number of physical pages in the simulation (typically 4)

table.getEntry(pageNumber) - returns the Page Table entry (a PTEntry object) for the given page number.

entry.isAccessed() - returns true if the Accessed/Second Chance bit is set; assumes "entry" is the variable name for the PTEntry object retrieved from the Page Table.

entry.setAccessed(boolean) - sets the Accessed/Second Chance but for the Page Table entry: true for 1 and false for 0.

HINT: Almost all of the work will be in the evict() method.

USE the optimal this is this is the code for FIFO

import java.util.LinkedList; import java.util.Queue; /** * This class contains the Memory Management methods called by the Simulator. * * Currently, this class implements the FIFO page replacement algorithm. * Modify this class with your page replacement algorithm. * * @author Adam Fischbach * @version Fall 2013 * */ public class MemoryManagerFIFO implements MemoryManager { private PageTable table; // Reference to the page table private Simulator sim; // Reference to the simulator /////////////////////////////////////////////////////////////////// /////////////////////////////// private Queue q; // Data structure for FIFO /////////////////////////////// /////////////////////////////////////////////////////////////////// private Queue freeList; // Queue of free frame numbers /** * Creates a new MemoryManager. Builds a free list containing all frames. * @param table reference to the page table * @param sim reference to the simulator * @param gui reference to the user interface */ public MemoryManagerFIFO(PageTable table, Simulator sim) { this.table = table; this.sim = sim; /////////////////////////////////////////////////////////////// /////////////////////////////// q = new LinkedList(); // Create data structure for FIFO /////////////////////////////// /////////////////////////////////////////////////////////////// freeList = new LinkedList(); for(int i=0; i

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 Databases Questions!