An advanced First Out (FIFO) algorithm for the OS page replacement algorithm

Source: Internet
Author: User
an advanced first-out (FIFO) algorithm for the OS page replacement algorithm

In the operating system page replacement algorithm, the simplest page replacement algorithm is FIFO algorithm. The FIFO page replacement algorithm records the amount of time that the page is transferred into memory for each page. When a page must be replaced, the oldest page is selected. Note that you do not need to record the exact time that a page was transferred. You can create a FIFO queue to manage all pages in memory. The first page in the queue will be replaced. When you need to dial the page, add it to the tail of the queue. The following will simulate the FIFO algorithm in the Java language, where the number of frames is 5, and the page number in the reference string does not contain 0.

Import java.util.LinkedList;
Import java.util.List;

public class FIFO {
public static void Main (string[] args) {
int framesize = 5; Number of Frames
Int[] s = {1, 2, 3, 4, 2, 1, 5, 6, 2, 1, 2, 3, 7, 6, 3, 2, 1, 2, 3, 6}; Reference string
Int[] is = new Int[s.length];
for (int i = 0; i < s.length; i++)
Is[i] = 0;
int aa[][] = new Int[s.length][framesize];
list<integer> q = new linkedlist<integer> ();
int count = 0;
for (int i = 0; i < framesize; i++)
Q.add (0);
for (int i = 0; i < s.length; i++) {
if (!q.contains (new Integer (s[i))) {
Q.remove (0);
Q.add (New Integer (s[i));
count++;
Is[i] = 1;
}
int j = 0;
for (Integer v:q)
Aa[i][j++] = v;
}
for (int i = 0; i < framesize; i++) {
for (int j = 0; J < S.length; J + +) {
System.out.print (Aa[j][i] + "");
}
System.out.println ();
}
System.out.println ();
for (int i = 0; i < s.length; i++) {
System.out.print (Is[i] + "");
}
System.out.println ();
System.out.println ("total:" + count);
}
}

The results of the implementation are as follows:

0 0 0 0 0 0 1 2 2 3 4 5 6 6 6 6 6 6 6-6
0 0 0 1 1 1 2 3 3 4 5 6 1 1 1 1 1 1 1-1
0 0 1 2 2 2 3 4 4 5 6 1 2 2 2 2 2 2 2-2
0 1 2 3 3 3 4 5 5 6 1 2 3 3 3 3 3 3 3-3
1 2 3 4 4 4 5 6 6 1 2 3 7 7 7 7 7 7 7-7
============================
1 1 1 1 0 0 1 1 0 1 1 1 1 0 0 0 0 0 0-0
Total:10

wherein, each column above the equal sign represents a queue, 0 represents an idle frame, and 1 below the equal sign represents a page replacement, and 0 indicates that no page replacement occurred.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.