




已阅读5页,还剩5页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
提示出错,重新输入NYYN结 束是否用其他算法继续S=? Msize加1Msize32 用户内存空间msize=2形成地址页号1S4输入算法号S生成地址流开 始 OPTFIFO12实验程序产生指令流文件produce_addstream.h#ifndef PRODUCE_ADDSTREAM_H#define PRODUCE_ADDSTREAM_H#include#include#include#include#include using namespace std;#define random(x) (rand()%x)#define MAX_LENGTH 320struct produceint num; /指令序号int zhiling; /指令地址int virtualpage; /指令虚页号produce *next;struct produce*creatlist();void insert(struct produce *first,struct produce *s); /插入一个节点(尾插法)void print(struct produce *first); /打印函数int max(vectorvector ,int );struct produce*creatlist()srand(int)time(0);struct produce*first=new produce;first-next=NULL;int m=0,m1=0;/*int yanzheng20=7,0,1,2,0,3,0,4,2,3,0,3,2,1,2,0,1,7,0,1;for (int i=0;inum=i*4+0;s0-zhiling=yanzhengi*4+0;s0-virtualpage=s0-zhiling;insert(first,s0);struct produce *s1;s1=new produce;s1-num=i*4+1;s1-zhiling=yanzhengi*4+1;s1-virtualpage=s1-zhiling;insert(first,s1);struct produce *s2;s2=new produce;s2-num=i*4+2;s2-zhiling=yanzhengi*4+2;s2-virtualpage=s2-zhiling;insert(first,s2);struct produce *s3;s3=new produce;s3-num=i*4+3;s3-zhiling=yanzhengi*4+3;s3-virtualpage=s3-zhiling;insert(first,s3);/*/*for (int i=0;inum=i*4+0;s0-zhiling=m+1;s0-virtualpage=s0-zhiling/10;insert(first,s0);m1=random(m+1);struct produce *s1;s1=new produce;s1-num=i*4+1;s1-zhiling=m1;s1-virtualpage=s1-zhiling/10;insert(first,s1);struct produce *s2;s2=new produce;s2-num=i*4+2;s2-zhiling=m1+1;s2-virtualpage=s2-zhiling/10;insert(first,s2);struct produce *s3;s3=new produce;s3-num=i*4+3;s3-zhiling=random(MAX_LENGTH-m1-2)+m1+2;s3-virtualpage=s3-zhiling/10;insert(first,s3);/*/return first;void insert(struct produce *first,struct produce *s)struct produce *r=first;struct produce *p;while(r)p=r;r=r-next;p-next=s;p=s;p-next=NULL;void print(struct produce *first) /打印函数struct produce *p;p =first-next;cout随机产生的指令的信息如下endl;cout指令序号 指令地址 指令虚页号endl;while (p)coutnumtzhilingsetw(14)virtualpagenext;int max(vectorvector page,int Maxpage)int a=0,position=0;for (int i=0;ia)a=pagei1;position=i;return position;#endif先来先出调度算法:fifo.h#ifndef FIFO_H#define FIFO_Hvoid fifo(struct produce *first,int Maxpage)vector page(Maxpage);/for (int i=0;inext;while (p)pages=p-virtualpage;for(int i=0;iMaxpage;i+)if (pagei=-1|count1next;coutFIFO调度算法缺页次数 缺页率 命中率endl;coutcount2setw(25)double(count2)/MAX_LENGTHsetw(10)1-double(count2)/MAX_LENGTHendl;#endif FIFO_HLRU调度算法lru.h#ifndef LRU_H#define LRU_H#includeusing namespace std;/int max(vectorvector ,int );void lru(struct produce*first,int Maxpage)struct produce*p=first-next;vectorvector page2(Maxpage, vector(2); int count1=0; /定义内存已经被占用的页数int count2=0; /定义记录缺页次数int equal=0; /定义判断如果当前页数与比较的页数,如果相等则为1,否则为0int place=0; /定义要替换的位置for (int i=0;iMaxpage;i+)page2i0=-1;page2i1=0;while (p)if (count1Maxpage)for (int i=0;ivirtualpage;count2+;break;else if (page2i0=p-virtualpage)page2i1 =1;count1+;elsefor (int i=0;ivirtualpage)equal=1;place=i;break;if (equal=1)page2place1 =1;equal=0;else place = max(page2,Maxpage);page2place1=1;page2place0=p-virtualpage;count2+;p=p-next;coutLRU调度算法缺页次数 缺页率 命中率endl;coutcount2setw(24)double(count2)/MAX_LENGTHsetw(10)1-double(count2)/MAX_LENGTHendl;#endif LRU_HOPT调度算法opt.h#ifndef OPT_H#define OPT_H#includeusing namespace std;int search(struct produce*place,int position);void opt(struct produce*first,int Maxpage)struct produce*p =first-next;vectorvector page3(Maxpage, vector(2);int count1=0; /定义内存已被使用的页数int count2=0; /定义缺页次数int current=0; /定义当前工作位置int equal=0; /定义判断如果当前页数与比较的页数,如果相等则为1,否则为0int place=0; /定义要替换的位置for (int i=0;iMaxpage;i+)page3i0=-1;page3i1=0;while (p)/cout1111endl;if (count1Maxpage)for (int i=0;ivirtualpage;page3i1=search(p,current);count2+;break;else if (page3i0=p-virtualpage)page3i1=search(p,current);count1+;elsefor (int i=0;ivirtualpage)equal=1;place=i;break;if (equal=1)page3place1 =search(p,current);equal=0;elseplace = max(page3,Maxpage);page3place1=search(p,current);page3place0=p-virtualpage;count2 +=1;p=p-next;current +=1;coutOPT调度算法缺页次数 缺页率 命中率endl;coutcount2setw(25)double(count2)/MAX_LENGTHsetw(10)1-double(count2)/MAX_LENGTHnext;int current=place-virtualpage;int position1=position+1;while(p)if (current=p-virtualpage)return position1;position1+;p=p-next;return position1;#endif主函数 控制台ccglmain.cpp#include#include produce_addstream.h#include fifo.h#include lru.h#include opt.hvoid main()int S; /定义变量记录用户选择char again; /定义变量用户选择继续还是退出cout开始产生内存指令endl;struct produce *first=creatlist();/产生随机指令cout打印产生的指令信息endl;print(first);/打印产生的指令信息while (1)int Maxpage=3;/定义内存最大页面数cout输入你的选择endl;cout1:FIFO(先进先出)调度算法n2:LRU(最近最少使用算法)n3:OPT(最佳淘汰算法)n4:清屏S;while(S4|S1)cout输入错误重新输入S;if (S
温馨提示
- 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年度影视拍摄车牌租赁服务协议
- 园林绿化资料范例
- 万达入职性格在线测评题
- 车位无偿使用补充协议书范本
- 中华人民共和国标准设计施工总承包招标文件(2012年版)
- Magic Tree House 神奇树屋词汇大全
- 《心系国防 有你有我》国防教育主题班会课件
- 教师工作法律风险防范省公开课金奖全国赛课一等奖微课获奖课件
- A类《职业能力倾向测验》2024年事业单位考试湘西土家族苗族自治州泸溪县统考试题含解析
- 渭南万泉330千伏变电站-雷家洼110千伏线路工程环境影响报告
- 新编文学理论课件
- 小学数学北师大版三年级下册递等式计算练习300题及答案
评论
0/150
提交评论