分区式存储管理Word格式文档下载.docx

上传人:b****5 文档编号:20809123 上传时间:2023-01-25 格式:DOCX 页数:14 大小:426.42KB
下载 相关 举报
分区式存储管理Word格式文档下载.docx_第1页
第1页 / 共14页
分区式存储管理Word格式文档下载.docx_第2页
第2页 / 共14页
分区式存储管理Word格式文档下载.docx_第3页
第3页 / 共14页
分区式存储管理Word格式文档下载.docx_第4页
第4页 / 共14页
分区式存储管理Word格式文档下载.docx_第5页
第5页 / 共14页
点击查看更多>>
下载资源
资源描述

分区式存储管理Word格式文档下载.docx

《分区式存储管理Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《分区式存储管理Word格式文档下载.docx(14页珍藏版)》请在冰豆网上搜索。

分区式存储管理Word格式文档下载.docx

}

2.内存占用区用链表描述,其结点类型描述如下:

structbusylink{

charname;

/*作业或进程名name=’S’表示OS占用

intlen,address;

structbusylink*next;

}

3.设全程量:

structfreelink*free_head=NULL;

//自由链队列(带头结点)队首指针

structbusylink*busy_head=NULL,//占用区队列队(带头结点)首指针

structbusylink*busy_tail=NULL;

//占用区队列队尾指针

三、主要函数设计

1.函数名称:

requireMemo(charname,intrequire)

功能描述:

在空闲区域链中找到第一个满足条件的结点,将其分配掉,如果结点的长度大于require,则剩下的又将作为一个空闲结点插入到空闲区域链中

输入参数:

charname,intrequire

输出参数:

程序流程图:

2.函数名称:

voidfreeMemo(charname)

功能描述:

找到要回收的结点,将其释放,并将这个结点重新插入到空闲区域链中去

输入参数:

charname

输出参数:

程序流程图:

将w插入到空闲区域链中时前的归并算法的流程图如下:

四、测试数据及运行结果

4.1测试数据准备

4.2运行结果及说明

1.测试目标:

运用按最佳适应算法[1](空闲区未归并时的)

运行结果:

2.测试目标:

运用按最佳适应算法(空闲区归并时的)

五、实验总结

首先,对链表又有进一步的理解,还有就是加深理解内存的分配与回收,分配与回收的策略,并掌握动态分区这种内存管理的具体实施方法。

再者,就是在编程中遇到的困难,在编写归并程序首先是自己考虑问题不全面,写的程序就只顾及到一个结点,而没有实现有两个结点的情况,于是后来再加了一条else语句,就没有出现问题。

还有一个问题就是将多余的结点free时也出现问题,加了一条if(s==NULL),成立就释放掉。

一开始把free语句写在while循环内,一旦把找到的结点释放掉,则找不到下一个结点,也会出错,所以应该把free放到while循环外。

六、参考文献

[1]左万历,周长林,彭涛.计算机操作系统教程.第3版.北京:

高等教育出版社,2010

附:

程序源代码

按最先适应算法

#include<

windows.h>

#include<

stdio.h>

stdlib.h>

structfreelink

{

intlen,address;

//len为分区长度;

structfreelink*next;

};

//内存占用区用链表描述,其结点类型描述如下:

structbusylink

charname;

//作业或进程名name='

S'

表示OS占用

intlen,address;

structbusylink*next;

};

//并设全程量:

//自由链队列带头结点)队首指针?

structbusylink*busy_head=NULL,*busy_tail=NULL;

//占用区队列队(带头结点)首指针

//占用区队列队尾指针

//设计子函数:

voidstart(void)/*设置系统初始状态*/

{

structfreelink*p;

structbusylink*q;

free_head=(structfreelink*)malloc(sizeof(structfreelink));

free_head->

next=NULL;

//创建自由链头结点

busy_head=busy_tail=(structbusylink*)malloc(sizeof(structbusylink));

busy_head->

//创建占用链头结点

p=(structfreelink*)malloc(sizeof(structfreelink));

p->

address=64;

len=640-64;

//(OS占用了64K)

next=p;

q=(structbusylink*)malloc(sizeof(structbusylink));

q->

name='

;

/*S表示操作系统占用*/

len=64;

address=0;

next=q;

busy_tail=q;

voidrequireMemo(charname,intrequire)/*模拟内存分配*/

structfreelink*w,*u,*v,*x,*y;

structbusylink*p;

x=free_head;

y=free_head->

next;

while((y!

=NULL)&

&

(y->

len<

require))//找到第一个满足条件的空闲区

{

x=y;

y=y->

}

if(y!

=NULL)

p=(structbusylink*)malloc(sizeof(busylink));

p->

name=name;

address=y->

address;

len=require;

busy_tail->

//把p插入到busy_head的尾部

busy_tail=p;

w=x->

x->

next=w->

if(w->

len==require)

{

free(w);

}

else

w->

address=w->

address+require;

len=w->

len-require;

u=free_head;

v=free_head->

while((v!

(v->

w->

len))//如果此结点还有多余,就此又重新插入到空闲区域链中(按照长度由小到大的次序排列)

{

u=v;

v=v->

}

u->

next=w;

next=v;

else

printf("

can'

tallocate!

\n"

);

voidfreeMemo(charname)/*模拟内存回收*/

structbusylink*p,*q;

structfreelink*w,*u,*v,*s1=NULL,*s2=NULL;

intlen,address;

intflag1=1,flag2=1;

p=busy_head->

while((p!

=NULL)&

(p->

name!

=name))//找到要回收的结点

q=p;

p=p->

if(p==NULL)

%cisnotexist\n"

name);

else

if(p==busy_tail)

busy_tail=q;

q->

next=p->

len=p->

len;

address=p->

free(p);

w=(structfreelink*)malloc(sizeof(freelink));

w->

len=len;

address=address;

u=free_head;

v=free_head->

while((v!

(flag1==1||flag2==1))//归并算法

if((w->

address==(v->

address+v->

len))&

flag1)

s1=v;

u->

next=s1->

w->

address=v->

len+=v->

v=v->

flag1=0;

elseif(((w->

address+w->

len)==v->

address)&

flag2)

s2=v;

next=s2->

flag2=0;

else

if(s1!

free(s1);

if(s2!

free(s2);

if(v!

len))

voidpast(inttime)/*模拟系统过了时间time,用Sleep(),或者用个空循环*/

Sleep(5);

时间%d后:

time);

voidprintlink()/*输出内存空闲情况(自由链的结点)*/

structfreelink*p;

p=free_head->

printf("

无空闲区!

while(p!

首地址:

%d\t长度:

%d\n"

p->

address,p->

len);

----------------------------------------\n"

voidprintlink1()/*输出内存占用的情况*/

无内存占有区!

名字:

%c\t首地址:

name,p->

//设计主函数:

intmain()

start();

past(5);

requireMemo('

A'

8);

B'

16);

C'

64);

D'

124);

内存占用区为:

printlink1();

内存空闲区为:

printlink();

past(10);

freeMemo('

past(15);

E'

50);

past(20);

);

return0;

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 法律文书 > 判决书

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1