




已阅读5页,还剩13页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
实 验 报 告(2014 / 2015 学年 第 一 学期)课程名称计算机操作系统实验名称虚拟存储中页面置换算法的模拟实现实验时间2014年12月19日指导单位南京邮电大学指导教师崔衍学生姓名班级学号学院(系)物联网院专 业网络工程实 验 报 告实验名称虚拟存储中页面置换算法的模拟实现指导教师崔衍实验类型上机实验实验学时4实验时间2014.12.19一、 实验目的和要求目的:通过请求页式存储管理中页面置换算法模拟设计,了解虚拟存储技术的技术特点,掌握请求页式存储管理的页面置换算法要求:(1)设计实现下面算法,并输出下述各种算法的命中率。 先进先出的算法(FIFO); 最近最少使用算法(LRR); 最佳淘汰算法(OPT)先淘汰最不常用的页地址。(2)多次反复运行改进后的程序,观察并记录运行结果,并分析原因。二、实验环境(实验设备)Vc+6.0二、 实验原理及内容实验三#include #include#include#include#define Bsize 4typedef struct BLOCK/声明一种新类型物理块类型 int pagenum;/页号 int accessed;/访问字段,其值表示多久未被访问BLOCK; int pc;/程序计数器,用来记录指令的序号int n;/缺页计数器,用来记录缺页的次数 static int temp320;/用来存储320条随机数BLOCK blockBsize; /定义一大小为4的物理块数组/*void init( ); /程序初始化函数int findExist(int curpage);/查找物理块中是否有该页面int findSpace( );/查找是否有空闲物理块int findReplace( );/查找应予置换的页面void display ( );/显示void suijishu( );/产生320条随机数,显示并存储到temp320void pagestring( );/显示调用的页面队列void OPT( );/OPT算法void LRU( );/ LRU算法void FIFO( );/FIFO算法/*void init( ) for(int i=0;iBsize;i+) blocki.pagenum=-1; blocki.accessed=0; pc=n=0; /-int findExist(int curpage) for(int i=0; iBsize; i+) if(blocki.pagenum = curpage ) return i;/检测到内存中有该页面,返回block中的位置 return -1;/-int findSpace( ) for(int i=0; iBsize; i+) if(blocki.pagenum = -1) return i;/找到空闲的block,返回block中的位置 return -1;/-int findReplace( ) int pos = 0; for(int i=0; iblockpos.accessed) pos = i;/找到应予置换页面,返回BLOCK中位置 return pos;/-void display( ) for(int i=0; iBsize; i+) if(blocki.pagenum != -1) printf( %02d,blocki.pagenum); coutpc; cout*按照要求产生的320个随机数:*endl; for(int i=0;i320;i+) tempi=pc; if(flag%2=0) pc=+pc%320; if(flag=1) pc=rand( )% (pc-1); if(flag=3) pc=pc+1+(rand( )%(320-(pc+1); flag=+flag%4; printf( %03d,tempi); if(i+1)%10=0) coutendl; /-void pagestring( ) for(int i=0;i320;i+) printf( %02d,tempi/10); if(i+1)%10=0) coutendl; /-void OPT( ) int exist,space,position ; int curpage; for(int i=0;i320;i+) if(i%100=0) getch( ); pc=tempi; curpage=pc/10; exist = findExist(curpage); if(exist=-1) space = findSpace ( ); if(space != -1) blockspace.pagenum = curpage; display( ); n=n+1; else for(int k=0;kBsize;k+) for(int j=i;j320;j+) if(blockk.pagenum!= tempj/10) blockk.accessed = 1000; /将来不会用,设置为一个很大数 else blockk.accessed = j; break; position = findReplace( ); blockposition.pagenum = curpage; display( ); n+; cout缺页次数:nendl; cout缺页率:(n/320.0)*100%endl;/- void LRU( ) int exist,space,position ; int curpage; for(int i=0;i320;i+) if(i%100=0) getch( ); pc=tempi; curpage=pc/10; exist = findExist(curpage); if(exist=-1) space = findSpace( ); if(space != -1) blockspace.pagenum = curpage; display( ); n=n+1; else position = findReplace( ); blockposition.pagenum = curpage; display( ); n+; else blockexist.accessed = -1;/恢复存在的并刚访问过的BLOCK中页面accessed为-1 for(int j=0; j4; j+) blockj.accessed+; cout缺页次数:nendl; cout缺页率:(n/320.0)*100%endl;/-void FIFO( ) int exist,space,position ; int curpage; for(int i=0;i320;i+) if(i%100=0) getch( ); pc=tempi; curpage=pc/10; exist = findExist(curpage); if(exist=-1) space = findSpace( ); if(space != -1) blockspace.pagenum = curpage; display( ); n=n+1; else position = findReplace( ); blockposition.pagenum = curpage; display( ); n+; blockposition.accessed-; for(int j=0; jBsize; j+) blockj.accessed+; cout缺页次数:nendl; cout缺页率:(n/320.0)*100%endl;/*void main( ) int select; cout请输入第一条指令号(0320):; suijishu( ); cout*对应的调用页面队列*endl; pagestring( ); do cout*endl; cout-1:OPT 2:LRU 3:FIFO 4:退出-endl; cout*endl; coutselect; cout*endl; init( ); switch(select) case 1:cout最佳置换算法OPT:endl; cout*endl; OPT( ); break; case 2:cout最近最久未使用置换算法LRU:endl; cout*endl; LRU( ); break; case 3:cout先进先出置换算法FIFO:endl; cout*endl; FIFO( ); break; default: ; while(select!=4);实验结果: 实验四Login用户登录bool chklogin(char *users, char *pwd)int i;for(i=0; itemp-filename;cintemp-content;if(recent-child=NULL)temp-parent=recent;temp-child=NULL;recent-child=temp;temp-prev=temp-next=NULL;cout文件建立成功!child;while(ttemp-next)ttemp=ttemp-next;if(strcmp(ttemp-filename,temp-filename)=0&ttemp-isdir=0)printf(对不起,文件已存在!);return 1;ttemp-next=temp;temp-parent=NULL;temp-child=NULL;temp-prev=ttemp;temp-next=NULL;cout文件建立成功!endl;return 1;int dir()int i=0,j=0;temp=new fnode;temp=recent;if(temp!=root)cout .child=NULL)coutTotal: directors i files j child;while(temp)if(temp-isdir)cout filenameendl;i+;elsecout filenamenext;coutTotal: directors ifiles j filename;if(recent-child=NULL)cout文件不存在!child-filename,filename)=0)coutchild-contentchild;while(temp-next)if(strcmp(temp-next-filename,filename)=0)coutnext-contentendl;return 1;cout文件不存在!filename;if(recent-child=NULL)cout文件不存在!child-filename,filename)=0)recent-child-isopen=1;/设置文件标记为打开cinrecent-child-content;recent-child-isopen=0;/设置文件标记为关闭cout文件写入成功!child;while(temp-next)if(strcmp(temp-next-filename,filename)=0)recent-child-isopen=1;/设置文件标记为打开cintemp-next-content;recent-child-isopen=0;/设置文件标记为关闭cout文件写入成功!endl;return 1;cout文件不存在!filename;temp=new fnode;if(recent-child)temp=recent-child;while(temp-next & (strcmp(temp-filename,filename)!=0 | temp-isdir!=0)temp=temp-next;if(strcmp(temp-filename,filename)!=0)cout不存在该文件!endl;return 0;elsecout不存在该文件!parent=NULL)temp-prev-next=temp-next;if(temp-next)temp-next-prev=temp-prev;temp-prev=temp-next=NULL;elseif(temp-next)temp-next-parent=temp-parent;temp-parent-child=temp-next;delete temp;cout文件已删除!temp-filename;if(recent-child=NULL)temp-parent=recent;temp-child=NULL;recent-child=temp;temp-prev=temp-next=NULL;elsettemp=recent-child;while(ttemp-next)ttemp=ttemp-next;if(strcmp(ttemp-filename,temp-filename)=0&ttemp-isdir=1)printf(对不起,目录已存在!);return 1;ttemp-next=temp;temp-parent=NULL;temp-child=NULL;temp-prev=ttemp;temp-next=NULL;return 1;切换目录int dir()int i=0,j=0;temp=new fnode;temp=recent;if(temp!=root)cout .child=NULL)coutTotal: directors i files j child;while(temp)if(temp-isdir)cout filenameendl;i+;elsecout filenamenext;coutTotal: directors ifiles j endl;四、实验小结(包括问题和解决方法、心得体会、意见与建议等)
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年事业单位工勤技能-湖南-湖南广播电视天线工四级(中级工)历年参考题库含答案解析
- 2025年事业单位工勤技能-湖北-湖北计量检定工二级(技师)历年参考题库典型考点含答案解析
- 2025年中药炮制新配方鉴定报告解析
- 2025年事业单位工勤技能-湖北-湖北放射技术员三级(高级工)历年参考题库含答案解析
- 2025年事业单位工勤技能-湖北-湖北城管监察员一级(高级技师)历年参考题库典型考点含答案解析
- 2025年事业单位工勤技能-湖北-湖北印刷工五级(初级工)历年参考题库典型考点含答案解析
- 2025年汽车轻量化车身材料市场发展趋势报告
- 2025年数字人民币跨境支付跨境支付系统安全评估与改进措施报告
- 深度探讨2025年废弃矿井资源再利用技术路径与产业创新驱动策略报告
- 2025年事业单位工勤技能-浙江-浙江食品检验工一级(高级技师)历年参考题库含答案解析(5套)
- 2025四川建筑安全员C证(专职安全员)考试题库
- 嘉兴市昊鸣纺织有限公司年产480万米高档纺织真丝面料技改项目环评报告
- 假体隆胸手术课件
- 水泵房设备安装施工方案
- 90题性格测试题及答案
- 农村宅基地流转合同协议范本
- 文保员安全培训课件
- 西门子S7-1200PLC应用技术项目教程(第2版)-教案全套 LAD+SCL
- 高锰酸钾的产品包装说明和使用说明书
- 2025年华侨港澳台生联招考试高考化学试卷试题(含答案解析)
- 开曼群岛公司法2024版中文译本(含2024年修订主要内容)
评论
0/150
提交评论