已阅读5页,还剩13页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
课本第九章21题 实验ytinrete1实验目的:学习页面置换算法2实验内容Write a program that implements the FIFO and LRU page-replacement algorithms presented in this chapter. First, generate a random page reference string where page numbers range from 0.9. Apply the random page-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页置换算法。首先产生一个随机的页面引用序列,页面数从09。将这个序列应用到每个算法并记录发生的页错误的次数。实现这个算法时,要将页帧的数量设为可变(从17)。假设使用请求调页。3 设计说明FIFO算法:每次请求先查找是否有空块,有则替换,并标记为最晚到达,若没有则从标记中寻找最新到达的块,替换,并更新标记表。标记数字越小,到达时间最早。LRU算法:每次请求先查找是否有空块,有则替换,并标记为最近使用时间最短者,若没有则从标记中寻找最近使用时间最长者,替换,并更新标记表。标记数字越小,最近使用频率越低。4实验环境windows7 ultimate x64 with sp1Dev-c+5 程序源码#include#include#include#include #include #include using namespace std;typedef struct block/页帧块结构 int num;int lable;block;int page_size, frame_size;/序列数,页帧大小 vector order;/存放序列vector 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; jtemp)(frame.at(j).lable-;/多余部分结束elsecout匹配失败!endl;error+;/开始置换/先查找空页for(int j=0; jframe.size(); j+)if(-1=(frame.at(j).num)position=j;break;if(-1!=position)/有空页 (frame.at(position).num=order.at(i);/置换seq+;(frame.at(position).lable=seq;/标记数字else/没有空页 for(int j=0; jframe.size(); j+)/找相应的置换项if(1=(frame.at(j).lable)position=j;break;(frame.at(position).num=order.at(i);/置换(frame.at(position).lable=seq+1;/标记进入顺序 for(int j=0; jframe.size(); j+)/更新标记(frame.at(j).lable-; cout引用后页帧情况(-1为空):;for(int j=0; jframe.size(); j+)cout(frame.at(j).num, ;coutendlendl;coutendl算法结束,总页错误的次数为:errorendlendl; int main()coutpage_size;if(page_size=0)cout序列数有误;return 0;coutframe_size;if(frame_size7)cout页帧数有误;return 0;int number;srand(unsigned(time(NULL);/设置随机数种子for(int i=0; ipage_size; i+)number=rand()%10;/页面数从0到9order.push_back(number);/* 课本例子,使用这个时将上面的随机数注释掉order.push_back(7);order.push_back(0);order.push_back(1);order.push_back(2);order.push_back(0);order.push_back(3);order.push_back(0);order.push_back(4);order.push_back(2);order.push_back(3);order.push_back(0);order.push_back(3);order.push_back(2);order.push_back(1);order.push_back(2);order.push_back(0);order.push_back(1);order.push_back(7);order.push_back(0);order.push_back(1);*/coutendl随机生成的页面引用序列为:endl;for(int i=0; iorder.size(); i+)coutorder.at(i);if(order.size()-1!=i)cout, ;coutendlendl;page_replacement (1);coutendlendl;page_replacement (2);system(pause);
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 产后创伤后应激障碍的识别与干预
- 产后抑郁的经颅磁刺激治疗参数优化
- 产后抑郁的共病焦虑障碍诊疗策略
- 交叉设计在生物等效性试验的缺失数据处理
- 子宫肉瘤进展-课件
- 云计算平台架构设计
- 慢性肾功能衰竭培训课件
- 初级财务会计及财务管理知识考试分析实务
- 初三教师的工作计划范例
- 经济学论文格式
- 档案工作者演讲稿
- 2025年新能矿业王家塔煤矿可行性研究报告
- 青马工程笔试题库及答案
- 财务风险防控管理体系建设方案
- 2025中小学诗词大会题题库(附答案)
- 综合实践活动:铅笔的探索与创新
- 机械专业英语试卷及答案
- 无人机培训课件范本图片
- 2025-2026学年沪书画版(五四学制)(2024)小学美术二年级上册(全册)教学设计(附目录P142)
- 窗口服务的课件
- 人工智能优化工业生产节能减排可行性分析报告
评论
0/150
提交评论