北邮操作系统试验页面置换算法.docxVIP

  • 12
  • 0
  • 约4.11千字
  • 约 18页
  • 2019-03-17 发布于广东
  • 举报
课本第九章21题 实验 ytinrete 1.实验目的: 学习页面置换算法 2.实验内容 Write a program that implements the FIFO and LRU replacement algorithms presented in this chapter. First, generate a random page reference string where page numbers range from 0..9. Apply the random reference string to each algorithm and record the number of page faults incurred by each algorithm. Implement the replacement algorithms such that the number of page frames can vary from 1..7. Assume that demand paging is used. 写一个程序来实现本章中介绍的FIFO和LRU页置换算法。首先产生一个随机的页面引用序列,页面数从0~9。将这个序列应用到每个算法并记录发生的页错误的次数。实现这个算法时,要将页帧的数量设为可变(从1~7)。假设使用请求调页。 设计说明 FIFO算法: 每次请求先查找是否有空块,有则替换,并标记为最晚到达,若没有则从标记中寻找最新到达的块,替换,并更新标记表。标记数字越小,到达时间最早。 LRU算法: 每次请求先查找是否有空块,有则替换,并标记为最近使用时间最短者,若没有则从标记中寻找最近使用时间最长者,替换,并更新标记表。标记数字越小,最近使用频率越低。 4.实验环境 windows7 ultimate x64 with sp1 Dev-c++ 程序源码 #includestdlib.h #includecstdlib #includetime.h #include iostream #include vector #include windows.h using namespace std; typedef struct block//页帧块结构 { int num; int lable; }block; int page_size, frame_size;//序列数,页帧大小 vector int order;//存放序列 vector block frame;//页帧 void page_replacement (int kind)//kind=1为FIFO,kind=2为LRU { //初始化 frame.clear(); block init; init.num=-1; init.lable=-1; for(int i=0; iframe_size; i++) { frame.push_back(init); } int error=0;//错误次数 int seq=0;//标记数字 int position=-1;//匹配位置 for(int i=0; iorder.size(); i++) { position=-1; couti:引用请求为 order.at(i) :endl; cout引用前页帧情况(-1为空):; for(int j=0; jframe.size(); j++) { cout(frame.at(j)).num, ; if(order.at(i)==(frame.at(j)).num) position=j; } coutendl; if(-1!=position) { cout匹配成功!endl; //更新标记这也是LRU算法比FIFO唯一多出来的地方 if(kind==2) { int temp=(frame.at(position)).lable; (frame.at(position)).lable=seq+1; for(int j=0; jframe.size(); j++) { if(-1!=(frame.at(j)).num)//不是空块 { if((frame.at(j)).labletemp) { (frame.at(j)).lable--; } } } } //多余部分结束 } else { cout匹配失败!endl; error++; //开始置换

文档评论(0)

1亿VIP精品文档

相关文档