模拟实现可变分区存储管理

上传人:今*** 文档编号:105740890 上传时间:2019-10-13 格式:DOCX 页数:33 大小:227.08KB
返回 下载 相关 举报
模拟实现可变分区存储管理_第1页
第1页 / 共33页
模拟实现可变分区存储管理_第2页
第2页 / 共33页
模拟实现可变分区存储管理_第3页
第3页 / 共33页
模拟实现可变分区存储管理_第4页
第4页 / 共33页
模拟实现可变分区存储管理_第5页
第5页 / 共33页
点击查看更多>>
资源描述

《模拟实现可变分区存储管理》由会员分享,可在线阅读,更多相关《模拟实现可变分区存储管理(33页珍藏版)》请在金锄头文库上搜索。

1、操作系统课程设计说明书题 目: 模拟实现可变分区存储管理 班 级: 学 号: 姓 名: 指导老师: 1目的和要求在熟练掌握计算机分区存储管理方式的原理的基础上,利用一种程序设计语言模拟实现操作系统的可变分区存储管理的功能,一方面加深对原理的理解,另一方面提高学生通过编程根据已有原理解决实际问题的能力,为学生将来进行系统软件开发和针对实际问题提出高效的软件解决方案打下基础。2设计内容设计合理的数据结构来描述存储空间:对于未分配出去的部分,可以用空闲分区队列或空闲分区链表来描述,对于已经分配出去的部分,由装入内存的作业占据,可以将作业组织成链表或数组。实现分区存储管理的内存分配功能,实现两种适应算

2、法:首次适应算法,最坏适应算法。实现分区存储管理的内存回收算法:要求能够正确处理回收分区与空闲分区的四种邻接关系。当碎片产生时,能够进行碎片的拼接。3设计环境Windows操作系统、DEV C+C语言4程序概要(1)数据结构和全局变量int type = 0; /算法类型/空闲分区struct freelink int len;/len为分区长度 int address; /address为分区起始地址 struct freelink *next;/占用分区struct busylink char name; /作业或进程名,name=S 表示OS占用int len;int address;s

3、truct busylink *next;struct freelink*free_head = NULL; /自由链队首指针 struct busylink *busy_head = NULL,/占用区队首指针 *busy_tail = NULL; /占用区队尾指针(2)功能模块划分 大体上可以将整个程序的模块划分成如下几个部分:1)主模块:主要是初始化(设置物理内存的用户区的大小,选取适应算法)和界面,界面参考如下:1-初始化2-作业进入内存3-作业完成4-显示当前自由分区5-显示当前作业占据分区6-碎片拼接7-退出2)内存分配算法(实现两种适应算法:最坏适应算法,首次适应算法)3)内存回

4、收算法(考虑四种邻接情况,尤其是采用最佳(坏)适应算法时的分区合并)4)碎片拼接算法5)空闲分区队列显示6)占用分区队列显示(3) 各函数调用关系(4) 主要函数流程图allocateMemoByWF();/两种算法分配回收大致相同,在这里只列举一种compactMemo()freeMemoByWF()5. 源代码#include #include #define MAX_SIZE 512/系统能分配的最大内存 #define FALSE 0#define TRUE 1int type = 0; /算法类型/空闲分区struct freelink int len;/len为分区长度 int a

5、ddress; /address为分区起始地址 struct freelink *next;/占用分区struct busylink char name; /作业或进程名,name=S 表示OS占用int len;int address;struct busylink *next;struct freelink*free_head = NULL; /自由链队列(带头结点)队首指针 struct busylink *busy_head = NULL,/占用区队列队(带头结点)首指针 *busy_tail = NULL; /占用区队列队尾指针/初始化 void init() struct free

6、link *p;struct busylink *q;free_head = (struct freelink*)malloc(sizeof(struct freelink);free_head-next = NULL; / 创建自由链头结点busy_head = busy_tail = (struct busylink*)malloc(sizeof(struct busylink);busy_head-next = NULL; / 创建占用链头结点p = (struct freelink *)malloc(sizeof(struct freelink);p-address = 64;p-le

7、n = MAX_SIZE - 64; /(OS占用了64K)p-next = NULL; free_head-next = p;q = (struct busylink *)malloc(sizeof(struct busylink);q-name = S; /S表示操作系统占用q-len = 64;q-address = 0;q-next = NULL;busy_head-next = q;busy_tail = q;/紧凑 struct freelink* compactMemo(int require) int sum = 0;struct freelink *fNode = free_

8、head-next;while (fNode != NULL) sum += fNode-len;fNode = fNode-next;printf(n);if (sum next;/让p一直指向第一个数据节点 while (p != NULL) free_head-next = p-next;free(p);p = free_head-next; /创建新的分区struct freelink *node = (struct freelink*)malloc(sizeof(struct freelink);node-address = 0;node-len = MAX_SIZE;free_he

9、ad-next = node;node-next = NULL;/修改占用区作业内存地址struct busylink *q = busy_head-next;while (q != NULL) q-address = node-address;node-len -= q-len;node-address += q-len;q = q-next; return node;/最坏(佳)适应算法在分区合并和分割后需要调整分区位置int adjust(struct freelink *node) struct freelink *p = free_head;/合并后链表中只剩一个分区if (p-ne

10、xt = NULL) free_head-next = node;node-next = NULL;return TRUE;while (p-next != NULL & node-len next-len) p = p-next;if (p-next = NULL) p-next = node;node-next = NULL;else node-next = p-next;p-next = node;return TRUE; /最坏适应算法 int allocateMemoByWF() int require;printf(请输入作业所需内存大小:);scanf(%d, &require)

11、;/判断第一个空闲分区大小是否满足需求struct freelink *p = free_head-next;if (p-len name);/检查是否重名struct busylink *temp = busy_head-next;while (temp != NULL & temp-name != q-name) temp = temp-next;if (temp != NULL) printf(该作业名已存在!n);return FALSE;q-len = require;q-address = p-address;q-next = NULL;/将作业按地址递增的顺序插入到作业队列中temp = busy_head;while(temp-next != NULL & q-address temp-next-address) temp = temp-next;if (temp-next = NULL) temp-next = q;q-next = NULL;else q-next = temp-next;temp-nex

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 高等教育 > 大学课件

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号