页面置换算法的模拟实现及命中率对比实验报告.docx_第1页
页面置换算法的模拟实现及命中率对比实验报告.docx_第2页
页面置换算法的模拟实现及命中率对比实验报告.docx_第3页
页面置换算法的模拟实现及命中率对比实验报告.docx_第4页
页面置换算法的模拟实现及命中率对比实验报告.docx_第5页
已阅读5页,还剩6页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

页面置换算法的模拟实现及命中率对比实验报告一、问题描述课程设计目的(1)、通过请求页式管理方式中页面置换算法的模拟设计,了解虚拟存储 术的特点,掌握请求页式存储管理中的页面置换算法。 (2)、课程设计内容模拟实现OPT(最佳置换)、FIFO和LRU算法,并计算命中率。(3) 、课程设计要求:a) 首先用随机数生成函数产生“指令”序列,然后将指令序列变换成相应的页地址流,再计算不同算法下的命中率。b) 通过随机数产生一个指令序列,共产生400条。其中50%的指令是顺序执行的(灵位50%就是非顺序),且25%的指令分布在前半部分地址空间,25%的指令分布在后半部分地址空间。c) 将指令地址流变换成页地址流d) 循环运行,使用户内存容量从4到40,。计算每个内存容量下不同页面置换算法的命中率。二、概要设计 1.程序的数据结构: #define total_instruction 100 /*指令流长*/#define M 100 /*实际页数*/#define N 5 /可用页面数struct Pro int num,time;int atotal_instruction;int pageN;2.程序的主函数:int main() Pro ptotal_instruction; Pro *page=new ProN; char c; int t=0,i; float n=0; Input(p); do for( i=0;iN;i+)/初试化页面基本情况 pagei.num=-1; pagei.time=2-i; printf(系统产生的随机数为:); for(int e=0;eM;e+) coutpe.num ; coutendl; i=0; coutf:FIFO页面置换endl; coutl:LRU页面置换endl; couto:OPT页面置换endl; cout按其它键结束c; if(c=f)/FIFO页面置换 n=0; cout页面置换情况: endl; while( i=0) i+;/找到相同的页面 else if(t=N)t=0; else n+;/ paget.num=pi.num; print(page); t+; cout缺页次数:n 命中率:1-n/total_instructionendl; if(c=l)/LRU页面置换 n=0; cout页面置换情况: endl; while(i=0) paget.time=0; else n+; t=Max(page); paget.num=pi.num; paget.time=0; for(int j=0;jN;j+) if(j!=t)pagej.time+; /*if(t=0)paget+1.time+;paget+2.time+; if(t=1)page2.time+;page0.time+; if(t=2)page1.time+;page0.time+;*/ if(k=-1) print(page); i+; cout缺页次数:n 命中率:1-n/total_instructionendl; if(c=o)/OPT页面置换 n=0; while(i=0)i+; else if(pageN-1.num=-1) for(int g=0;gN;g+) if(pageg.num=-1) pageg.num=pi.num; i+; n+; print(page); break; else int temp=-1,cn; for(t=0;tN;t+) if(tempCompfu(page,i,t,p) temp=Compfu(page,i,t,p); cn=t; pagecn=pi; n+; print(page); i+; cout缺页次数:n 命中率:1-n/total_instructionendl; while(c=f|c=l|c=o); return 0;三、详细设计程序代码如下:#include#include#include#includeusing namespace std;#define total_instruction 100 /*指令流长*/#define M 100 /*实际页数*/#define N 5 /可用页面数struct Pro int num,time;int atotal_instruction;int pageN;void Input(Pro ptotal_instruction) int m,i,m1,m2; srand( (unsigned int )time(NULL); m=rand( )%400; / for(i=0;itotal_instruction;) /*产生指令队列*/ if(m399) printf(When i=%d,Error,m=%dn,i,m); exit(0); ai=m; /*任选一指令访问点m*/ ai+1=ai+1; ai+2=ai+2; /*顺序执行两条指令*/ int m1=rand( )%m; /*执行前地址指令m1 */ ai+3=m1; ai+4=m1+1; ai+5=m1 + 2;/*顺序执行两条指令*/ / s=(158-ai+5)*rand( )/32767/32767/2+ai+5+2; m2 = rand()%(157-m1)+m1+3; ai+6=m2; if( (m2+2) 159 ) ai+7 = m2+1; i +=8; else ai+7 = m2+1; ai+8 = m2+2; i = i+9; m = rand()%m2; for (i=0;itotal_instruction;i+) /*将指令序列变换成页地址流*/ pi.num=ai/10; pi.time = 0; void print(Pro *page1)/打印当前的页面 Pro *page=new ProN; page=page1; for(int i=0;iN;i+) printf(%-4d,pagei.num); /coutpagei.num ; coutendl; /free(page);int Search(int e,Pro *page1 ) Pro *page=new ProN; page=page1; for(int i=0;iN;i+)if(e=pagei.num)return i; return -1;int Max(Pro *page1) Pro *page=new ProN; page=page1; int e=page0.time,i=0; while(iN)/找出离现在时间最长的页面 if(epagei.time)e=pagei.time; i+; for( i=0;iN;i+)if(e=pagei.time)return i; return -1;int Compfu(Pro *page1,int i,int t,Pro pM) Pro *page=new ProN; page=page1; int count=0; for(int j=i;jM;j+) if(paget.num=pj.num )break; else count+; return count;int main() Pro ptotal_instruction; Pro *page=new ProN; char c; int t=0,i; float n=0; Input(p); do for( i=0;iN;i+)/初试化页面基本情况 pagei.num=-1; pagei.time=2-i; printf(系统产生的随机数为:); for(int e=0;eM;e+) coutpe.num ; coutendl; i=0; coutf:FIFO页面置换endl; coutl:LRU页面置换endl; couto:OPT页面置换endl; cout按其它键结束c; if(c=f)/FIFO页面置换 n=0; cout页面置换情况: endl; while( i=0) i+;/找到相同的页面 else if(t=N)t=0; else n+;/ paget.num=pi.num; print(page); t+; cout缺页次数:n 命中率:1-n/total_instructionendl” if(c=l)/LRU页面置换 n=0; cout页面置换情况: endl; while(i=0) paget.time=0; else n+; t=Max(page); paget.num=pi.num; paget.time=0; for(int j=0;jN;j+) if(j!=t)pagej.time+; /*if(t=0)paget+1.time+;paget+2.time+; if(t=1)page2.time+;page0.time+; if(t=2)page1.time+;page0.time+;*/ if(k=-1) print(page); i+; cout缺页次数:n 命中率:1-n/total_instructionendl; if(c=o)/OPT页面置换 n=0; while(i=0)i+; else if(pageN-1.num=-1) for(int g=0;gN;g+) if(pageg.num=-1) pageg.num=pi.num; i+; n+; print(page); break; else int temp=-1,cn; for(t=0;tN;t+) if(tempCompfu(page,i,t,p) temp=Compfu(page,i,t,p); cn=t; pagecn=pi; n+; print(page); i+; cout缺页次数:n 命

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论