/*
* memory.c
*
* Created on: Jun 9, 2010
* Author: WangYun
*/
#include<stdio.h>
#define PAGE_NUM 20
#define BLOCK 3
void get_page(int page_seq[])
{
int i=PAGE_NUM;
printf("Please input %d numbers,which is the sequence of page number "
"such as(7 0 1 8 ...)\n",i);
for(i=0;i<PAGE_NUM;i++)
scanf("%d",&page_seq[i]);
}
int sum_found(int found[])
{
int i;
int sum=0;
for(i=0;i<BLOCK;i++)
sum+=found[i];
return sum;
}
int opt(int page_seq[])
{
int p;
int i,j;
int found[BLOCK]={0};
int block[BLOCK];
int lack=0;
for(i=0;i<BLOCK;i++) /*Initiate the physical block*/
block[i]=-1;
for(i=0;i<PAGE_NUM;i++)
{
for(p=0;p<BLOCK;p++)
found[p]=0;
for(p=0;p<BLOCK;p++)
if(block[p]==page_seq[i])
break;
if(p==BLOCK) /*Not find the page in the physical b
页面置换算法(FIFO,LRU,OPT)c模拟
最新推荐文章于 2022-12-02 16:31:47 发布
本文介绍了如何使用C语言模拟三种页面置换算法:先入先出(FIFO)、最近最少使用(LRU)和最佳(OPT)算法。通过实例分析和代码实现,深入理解这些算法的工作原理及其在内存管理和缓存优化中的应用。
摘要由CSDN通过智能技术生成