- 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++;
//开始置换
您可能关注的文档
最近下载
- 支部党员大会会议记录(支委会选举范例).docx VIP
- 深圳市宝安区2025-2026学年第一学期五年级语文期末学业质量评估卷(原卷+答案)统编版.docx VIP
- 山桐子种植加工、旅游项目可行性研究报告商业计划书.docx VIP
- 山桐子种植及种苗培育种植加工可行性研究报告申请备案.doc VIP
- 和田地区2026年度地直机关公开遴选公务员、事业单位公开选聘工作人员备考题库及完整答案详解1套.docx VIP
- 山桐子合作种植协议合同.docx VIP
- 2025年香氛未来趋势报告-英敏特.docx VIP
- 报告正文2014年太阳绿宝.pdf VIP
- 2025年高考:云南物理--试题及答案.pdf VIP
- 广东省深圳市宝安区2025-2026学年五年级上学期期末学业质量评估语文试卷.docx VIP
原创力文档

文档评论(0)