文档详情

实验一:分页存储管理模拟实验.doc

发布:2017-06-04约3.28千字共4页下载文档
文本预览下载声明
实验一:分页存储管理模拟实验 1.实验要求:掌握分页存储管理的基本概念和实现方法。要求编写一个模拟的分页管理程序,能对一个已有的程序实现分页显示。 2.数据结构: (1) 数据文件:在磁盘上创建一个包含1000个数据的文件data.txt。从0开始,每100个数为一页。 (2) 页面映像表包括:页号、中断位、块号。 (3) 内存缓冲区:申请存放300个字的缓冲区,设每100个字为一个内存块。初始状态:将数据文件的第一个页面装入到该缓冲区的第0块。 (4) 页面置换表:页面置换表的表项为3项,一个替换指针。采用先进先出页面置换算法。 3.程序算法: (1 )主程序:建立一个用户数据文件,初始化操作系统的数据结构;并装入用户数据文件的第一页。 (2) 调页程序:当读入数据的逻辑地址对应的块不在内存时,调用调页程序。该程序负责从数据文件中调入所需的页。 (3) 置换算法:当内存缓冲区中没有空闲块时,依置换策略选择一个可置换的页。 4.源程序 #includestdio.h #includestdlib.h struct data { int page; int block; int flag; }number[10]; struct rename { int block; int page; }name[4]; int main() { FILE *fp; int count1,count2,replace=0; int buffer1[10][100],buffer2[10][100]; char num; for(count1=0;count110;count1++) for(count2=0;count2100;count2++) buffer1[count1][count2]=100*count1+count2; if((fp=fopen(data.txt,wb))==NULL) { fprintf(stderr,error opening file .); system(pause); exit(1); } if(fwrite(buffer1,sizeof(int),1000,fp)!=1000) { fprintf(stderr,error writing file .); exit(1); } if(fclose(fp)==EOF) { printf(\nclose file error); exit(1); } printf(The page The block\n); for(count1=0;count14;count1++) { if((fp=fopen(data.txt,rb))==NULL) { fprintf(stderr,error opening file .); exit(1); } fseek(fp,100*sizeof(int)*count1,0); if(fread(buffer2[count1],sizeof(int),100,fp)!=100) { fprintf(stderr,error writing file .); exit(1); } if(fclose(fp)==EOF) { printf(\nclose file error); exit(1); } printf( %d %d \n,count1,count1); } for(count1=0;count110;count1++) { if(count14) { number[count1].page=count1; number[count1].block=count1; number[count1].flag=0; } else{ number[count1].page=count1; number[count1].block=count1; number[count1].flag=1; } } for(count1=0;count14;count1++) { name[count1].page=count1;
显示全部
相似文档