课本第九章21 题 实验 ytinrete 1.实验目的: 学习页面置换算法 2.实验内容 Write a program that implements the FIFO and LRU page-replacement algorithms presented in this chapter. First, generate a random page reference string where page numbers range from 0..9. Apply the random page-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)。假设使用请求调页。 3.设计说明 FIFO 算法: 每次请求先查找是否有空块,有则替换,并标记为最晚到达,若没有则从标记中寻找最新到达的块,替换,并更新标记表。标记数字越小,到达时间最早。 LRU 算法: 每次请求先查找是否有空块,有则替换,并标记为最近使用时间最短者,若没有则从标记中寻找最近使用时间最长者,替换,并更新标记表。标记数字越小,最近使用频率越低。 4.实验环境 windows7 ultimate x64 with sp1 Dev-c++ 5 .程序源码 #include #include #include #include #include #include using namespace std; typedef struct block//页帧块结构 { int num; int lable; }block; int page_size, frame_size;//序列数,页帧大小 vector order;//存放序列 vector 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; i