- 1、本文档共6页,可阅读全部内容。
- 2、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
实验七 页面置换算法的模拟实现报告川农
实验7 页面置换算法的模拟实现三、实验内容与步骤1、定义相关数据#define InitPysiBlocks 4#define MaxPages 16:unsigned int PysicalBlocks[InitPysiBlocks] = { 0 };unsigned int PageSequence[30] = { 1,2,3,6,4,7,3,2,1,4,7,5,6,5,2,1};2、按照教材中FIFO、LRU算法描述进行算法设计unsigned FIFO(unsigned *py,unsigned *pg)unsigned LRU(unsigned *py,unsigned *pg)3、查看运行结果是否与手工计算一致。四、实验材料的提交与成绩评定1.代码:#includeiostreamusing namespace std;#define InitPysiBlocks 4#define MaxPages 16unsigned int PysicalBlocks[InitPysiBlocks] = { 0 };unsigned int PageSequence[30] = { 1,2,3,6,4,7,3,2,1,4,7,5,6,5,2,1 };//FIFO算法unsigned FIFO(unsigned *py, unsigned *pg){//初始化填满数据for (int i = 0; i InitPysiBlocks; i++){py[i] = pg[i];}cout FIFO置换过程如下: endl;cout py[0] py[1] py[2] py[3] endl;//判断新获取数据进来的时间int time[4] = { 3,2,1,0 };//开始检测for (int i = 4; i MaxPages; i++){for (int j = 0; j InitPysiBlocks; j++){//如果新获取的已存在,直接输出if (py[0] == pg[i] || py[1] == pg[i] || py[2] == pg[i] || py[3] == pg[i]){cout py[0] py[1] py[2] py[3] endl;break;}else{for (int k = 0; k 4; k++){if (time[k] == 3){time[k] = 0;py[k] = pg[i];}else{time[k]++;}}cout py[0] py[1] py[2] py[3] endl;break;}}}cout 置换结束 endl;return 0;}//LRU算法//LRU辅助函数:返回除某一排下标后数组中最大元素下标int Max(unsigned *py, int te){int max = 0;int index = -1;for (int i = 0; i InitPysiBlocks; i++){if (i == te){continue;}else{if (py[i] max){max = py[i];index = i;}else{continue;}}}return index;}unsigned LRU(unsigned *py, unsigned *pg){//初始化填满数据for (int i = 0; i InitPysiBlocks; i++){py[i] = pg[i];}cout LRU置换过程如下: endl;cout py[0] py[1] py[2] py[3] endl;//判断新获取数据进来的时间unsigned time[4] = { 3,2,1,0 };//统计命中次数int count[4] = { 0 };//开始检测for (int i = InitPysiBlocks; i 16; i++){for (int j = 0; j InitPysiBlocks; j++){//如果新获取的已存在,直接输出,并将对应的命中变为1if (py[0] == pg[i] || py[1] == pg[i] || py[2] == pg[i] || py[3] == pg[i]){cout py[0] py[1] py[2] py[3] endl;if (py[0] == pg[i]){count[0] = 1;}else if (py[1] == pg[i]){count[1] = 1;}else if (py[2] == pg[i]){count[2] = 1;}else if (p
文档评论(0)