FIFO page replacement algorithm and fifo Algorithm

Source: Internet
Author: User

FIFO page replacement algorithm and fifo Algorithm

In this article, the {,} of the sequence length 20, and page 4; are used as an example;

1 # include <stdio. h> 2 3 # define InitPysiBlocks 4 4 # define MaxPages 20 5 int PysicalBlocks [InitPysiBlocks] = {-1,-1,-1,-1 }; 6 int PageSequence [MaxPages] = {,}; 7 8 void FIFO (int py [], int pg []) 9 {10 int I, q, j, table [InitPysiBlocks] [MaxPages]; 11 char flag, f [MaxPages]; 12 for (I = 0; I <MaxPages; I ++) 13 {14 q = 0; 15 while (pg [I]! = Py [q] & q! = InitPysiBlocks) 16 q ++; 17 if (q = InitPysiBlocks) 18 flag = '*'; 19 else20 flag = ''; 21 if (flag = '*') 22 {23 for (j = InitPysiBlocks-1; j> 0; j --) 24 py [j] = py [j-1]; 25 py [0] = pg [I]; 26} 27 for (j = 0; j <InitPysiBlocks; j ++) 28 table [j] [I] = py [j]; 29 f [I] = flag; 30} 31 printf ("the output result is the following table (-1 indicates null, * Indicates missing pages): \ n "); 32 for (I = 0; I <InitPysiBlocks; I ++) 33 {34 for (j = 0; j <MaxPages; j ++) 35 printf ("% 3d", table [I] [j]); 36 printf ("\ n"); 37} 38 for (I = 0; I <MaxPages; I ++) 39 printf ("% 3c", f [I]); 40 printf ("\ n"); 41} 42 43 void main () 44 {45 FIFO (PysicalBlocks, PageSequence); 46}

Result:

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.