页面置换算法模拟实验报告材料.docx

word试验编号4名称页面置换算法模拟试验目的通过恳求页式储备治理中页面置换算法模拟设计,以便:1、明白虚拟储备技术的特点2、把握恳求页式储备治理中页面置换算法试验内容与步骤 word 试验编号 4 名称页面置换算法模拟 试验目的 通过恳求页式储备治理中页面置换算法模拟设计,以便: 1、明白虚拟储备技术的特点 2、把握恳求页式储备治理中页面置换算法 试验内容与步骤 FIFO 和 LRU 算法运算拜访命中率; 设计一个虚拟储备区和内存工作区,并使用 程序设计 先用 srand()函数和 rand() 函数定义和产生指令序列, 址流,并针对不同的算法运算相应的命中率; 程序 1 然后将指令序列变换成相应的页地 #include windows.h //Windows GetCurrentProcessId() 需要 版,随机函数需要, //#include stdlib.h //Linux 版,随机函数 srand 和 rand 需要 #include stdio.h //printf() 需要 #define TRUE 1 #define FALSE 0 #define INV ALID -1 #define NULL 0 #define total_instruction 320 #define total_vp 32 #define clear_period 50 //共 320 条指令 // 虚存页共 32 页 // 拜访次数清零周期 typedef struct{ // 定义页表结构类型〔页面映射表 PMT 〕 int pn, pfn, counter, time; // 页号、页框号 (块号 )、一个周期内拜访该页面的次数、拜访时 间 }PMT; PMT pmt[32]; typedef struct pfc_struct{ // 页面掌握结构 1 / 8 wordint pn, pfn;struct pfc_struct *next;}pfc_type; pfc_type pfc[32];pfc_type *freepf_head,*busypf_head,*busypf_tail;//闲暇页头指针,忙页头指针,忙页尾指针int NoPageCount; // 缺页次数int a[total_instruction]; // 指令流数组int page[total_instruction], offset[total_instruction];// 每条指令的页和页内偏移void initialize( int );void FIFO( int ); void LRU( int );void NRU( int );//先进先出//最近最久未使用// word int pn, pfn; struct pfc_struct *next; }pfc_type; pfc_type pfc[32]; pfc_type *freepf_head,*busypf_head,*busypf_tail; //闲暇页头指针,忙页头指针,忙页尾指针 int NoPageCount; // 缺页次数 int a[total_instruction]; // 指令流数组 int page[total_instruction], offset[total_instruction]; // 每条指令的页和页内偏移 void initialize( int ); void FIFO( int ); void LRU( int ); void NRU( int ); //先进先出 //最近最久未使用 // 最近最不常常使用 /**************************************************************************** main() *****************************************************************************/ void main(){ int i,s; //srand(10*getpid()); //用进程号作为初始化随机数队列的种子 //Linux 版 srand(10*GetCurrentProcessId()); // 用进程号作为初始化随机数的种子 //Windows 版 s=rand()%320; //在[0 , 319] 的指令地址之间随机选取一起点 m for(i=0;itotal_instruction;i+=4){ if(s0||s319){ // 产生指令队列 printf(when i==%d,error,s==%d\n,i,s); exit(0); } a[i]=s; //任意选

文档评论(0)

1亿VIP精品文档

相关文档