FIFO页面置换算法_第1页
FIFO页面置换算法_第2页
FIFO页面置换算法_第3页
FIFO页面置换算法_第4页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

FIFO页面置换算法 1 假设每个页面中可存放10条指令 分配给作业的内存块数为4 2 用C语言模拟一个作业的执行过程 该作业共有320条指令 即它的地址空间为3 2页 目前它的所有页都还未调入内存 在模拟过程中 如果所访问的指令已在内存 则显示其物理地址 并转下一条指令 如果所访问的指令还未装入内存 则发生缺 页 此时需记录缺页的次数 并将相应页调入内存 如果4个内存块均已装入该作业 则需进行页面置换 最后显示其物理地址 并转下一条指令 在所有320指令执行完毕后 请计算并显示作业运行过程中发生的缺页率 3 置换算法 先进先出FIFO算法 include include include define N 4 define size 320 typedef struct Block int block num 块号 int page num 页号 struct Block next BLOCK BLOCKLIST typedef struct instruct 指令数据结构 int address 指令地址 int page num 指令所存的页号 INSTRUCTION INSTRUCTIONLIST INSTRUCTION instructions size 定义320条指令 BLOCKLIST block head front in block head指向块链表的头 front in指向最老的页面 即被淘汰的页面 int diseffect 0 缺页次数 int blockSize 0 标记块是否满 初始化指令 void Init Instructions for int i 0 i 320 i instructions i address rand 320 for int k 0 k 320 k instructions k page num int instructions k address 10 初始化块 循环链表 BLOCKLIST Init block BLOCKLIST head BLOCKLIST malloc sizeof BLOCK BLOCKLIST p for int i 1 inext BLOCKLIST malloc sizeof BLOCK p p next p block num i p page num 1 p next head return head 显示块内的数据 void display INSTRUCTION instructions BLOCKLIST p block head printf The new page page num d address d n instructions page num instructions address printf block num page num n do printf 2d 10d n p block num p page num p p next while p block head 显示页面对应的物理地址 void show physical address BLOCKLIST printf physical address address p block num 1024 instructions address 10 printf d n n address 查找该页是否存在 存在不要置换 否则置换 int Find page in block INSTRUCTION instructions BLOCKLIST do if p page num instructions page num return 1 p p next while p block head return 0 用于将四个块填满 void loadpage INSTRUCTION instructions BLOCKLIST p p block head while p page num 1 p p next p page num instructions page num blockSize 按FIFO置换页面 void replace page INSTRUCTION instructions BLOCKLIST p front in front in front in next void main BLOCKLIST p Init Instructions block head Init block front in block head for int i 0 i size i if Find page in block instructions i p display instructions i show physical address p instructions i getchar continue else if blockSize N diseffect loadpage instructions i display instructions i else diseffect replace page instructions i p display instruc

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论