FIFO and LRU Algorithm (Java)

xiaoxiao2021-03-06  32

/ * * Created on 2004-12-25 * * Todo to change the template for this generated file go to * window - preferences - java - code style - code templates * /

/ ** * @michelangelo * * Todo to change the Template for this generated type comment Go to * window - preferences - java - code style - code templates * /

Import java.util. *; public class testReplacement {

/ ** * * / private final int arraysize = 20; private int digitaray [] = new int [arraysize]; // private int digitaray [] = {1, 2, 3, 4, 2, 1, 5, 6, 2, 1, 2, 3, 7, 6, 3, 2, 1, 2, 3, 6}; private static final int frameesize [] = {1, 2, 3, 4, 5, 6, 7}; private Static int errorcount = 0; Vector frame = new vector (); public testReplacement () {super (); // Todo auto-generated constructor stub}

Public static void main (string [] args) {testReplacement at = new testReplacement (); at.generanderandomDigit (); at.output (); system.out.println ("---------- -Using FIFO -------------- "); system.out.println (); for (int i = 0; i

}}} Public void LRUREPLACE (INT FS) {Boolean FindTheSame = false; int pre = -1; // Store INT FLAG = -1; for (int J = 0; j

}}}}} PUBLIC VOID FIFOREPLACE (INT FS) {// Boolean Blank = true; // Whether the filling I = 0; for (int J = 0; j Temp) {TEMP = ((couple) frame.ementat ( I)))))). Time; index = i;}} for (i = 0; i

Algorithm idea: Use a vector to simulate the page table, and the number of coups thrown in is the size of the table. Time in COME Sets the Aging Time (FIFO) or Unused Period (LRU), Value is the value of DigitalAta [] in the request sequence. The sequence length is 20 to 0-9 generated by the random function. Framesize [] is stored in the size of the page table (that is, to throw a few couples) FIFO: When initialization, first empty, put the COutle, set the order of their time attributes to FrameSize, Frame-1 , Frame-2 ....... 1. The better the value, the sooner, the value of Value is all-in-1. The next job is to dispose of Value and Time. If Value match is found in Value in the Value in the Vector, PASS is found. If you don't find it, you will find the oldest in Time, (Whose Time is the oldest), find it to turn its value into the corresponding page value, put it Time = 1. For the oldest If you add their age.

LRU: When you initialize, you will be emptied first, place their Time property - 1, VALUE. Next, the request sequence is processed. If you find a corresponding page in Value, you set the corresponding TIME 0. Other coups corresponding to Time-. If you don't find it, find a least recently used (the corresponding Time's most negative That), find it later to replace its value to the request page value and put its TIME 0. At the same time, other Time -.

转载请注明原文地址:https://www.9cbs.com/read-62559.html

New Post(0)