实验二存储器的分配与回收算法实现Word文件下载.docx

上传人:b****2 文档编号:4403235 上传时间:2023-05-03 格式:DOCX 页数:17 大小:22.91KB
下载 相关 举报
实验二存储器的分配与回收算法实现Word文件下载.docx_第1页
第1页 / 共17页
实验二存储器的分配与回收算法实现Word文件下载.docx_第2页
第2页 / 共17页
实验二存储器的分配与回收算法实现Word文件下载.docx_第3页
第3页 / 共17页
实验二存储器的分配与回收算法实现Word文件下载.docx_第4页
第4页 / 共17页
实验二存储器的分配与回收算法实现Word文件下载.docx_第5页
第5页 / 共17页
实验二存储器的分配与回收算法实现Word文件下载.docx_第6页
第6页 / 共17页
实验二存储器的分配与回收算法实现Word文件下载.docx_第7页
第7页 / 共17页
实验二存储器的分配与回收算法实现Word文件下载.docx_第8页
第8页 / 共17页
实验二存储器的分配与回收算法实现Word文件下载.docx_第9页
第9页 / 共17页
实验二存储器的分配与回收算法实现Word文件下载.docx_第10页
第10页 / 共17页
实验二存储器的分配与回收算法实现Word文件下载.docx_第11页
第11页 / 共17页
实验二存储器的分配与回收算法实现Word文件下载.docx_第12页
第12页 / 共17页
实验二存储器的分配与回收算法实现Word文件下载.docx_第13页
第13页 / 共17页
实验二存储器的分配与回收算法实现Word文件下载.docx_第14页
第14页 / 共17页
实验二存储器的分配与回收算法实现Word文件下载.docx_第15页
第15页 / 共17页
实验二存储器的分配与回收算法实现Word文件下载.docx_第16页
第16页 / 共17页
实验二存储器的分配与回收算法实现Word文件下载.docx_第17页
第17页 / 共17页
亲,该文档总共17页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

实验二存储器的分配与回收算法实现Word文件下载.docx

《实验二存储器的分配与回收算法实现Word文件下载.docx》由会员分享,可在线阅读,更多相关《实验二存储器的分配与回收算法实现Word文件下载.docx(17页珍藏版)》请在冰点文库上搜索。

实验二存储器的分配与回收算法实现Word文件下载.docx

实验内容:

1.本实验是模拟操作系统的主存分配,运用可变分区的存储管理算法设计主存分配和回收程序,并不实际启动装入作业。

2.采用最先适应法、最佳适应法、最坏适应法分配主存空间。

3.当一个新作业要求装入主存时,必须查空闲区表,从中找出一个足够大的空闲区。

若找到的空闲区大于作业需要量,这是应把它分成二部分,一部分为占用区,加一部分又成为一个空闲区。

4.当一个作业撤离时,归还的区域如果与其他空闲区相邻,则应合并成一个较大的空闲区,登在空闲区表中。

5.设计的模拟系统中,进程数不小于5,进程调度方式可以采用实验一中的任何一种。

6.运行所设计的程序,输出有关数据结构表项的变化和内存的当前状态。

实验要求:

1.详细描述实验设计思想、程序结构及各模块设计思路;

2.详细描述程序所用数据结构及算法;

3.明确给出测试用例和实验结果;

4.为增加程序可读性,在程序中进行适当注释说明;

5.认真进行实验总结,包括:

设计中遇到的问题、解决方法与收获等;

6.实验报告撰写要求结构清晰、描述准确逻辑性强;

7.实验过程中,同学之间可以进行讨论互相提高,但绝对禁止抄袭。

代码实现:

#include<

stdio.h>

malloc.h>

#defineNULL0

#defineLEN1sizeof(structjob)//作业大小

#defineLEN2sizeof(structidle)//空闲区单元大小

#defineLEN3sizeof(structallocate)//已分配区单元大小

intSPACE=100;

//定义内存空间大小

intORIGI=1;

//定义内存起始地址

structjob//定义作业

{

intname;

intsize;

intaddress;

};

structidle//定义空闲区

structidle*next;

structallocate//定义已分配区

structallocate*next;

structidle*creatidle(void)//建立空闲表

structidle*head;

structidle*p1;

p1=(structidle*)malloc(LEN2);

p1->

size=SPACE;

address=ORIGI;

next=NULL;

head=p1;

return(head);

}

structallocate*creatallocate(void)//建立已分配表

structallocate*head;

head=NULL;

structjob*creatjob(void)//建立作业

structjob*p;

p=(structjob*)malloc(LEN1);

printf("

请输入要运行的作业的名称与大小:

\n"

);

scanf("

%d%d"

&

p->

name,&

size);

return(p);

structidle*init1(structidle*head,structjob*p)//首次适应算法分配内存

structidle*p0,*p1;

structjob*a;

a=p;

p0=head;

p1=p0;

while(p0->

next!

=NULL&

&

p0->

size<

a->

size)

{

p0=p0->

next;

}

if(p0->

size>

p0->

size=p0->

size-a->

size;

a->

address=p0->

address;

p0->

address+a->

else

printf("

无法分配\n"

structidle*init2(structidle*head,structjob*p)//最优

if(p0==NULL)

无法进行分配!

p0=p0->

无法分配!

while(p0!

=NULL)

p1->

{

p0=p0->

}

elseif((p0->

size)&

(p0->

size))

p1=p0;

size=(p1->

size)-(a->

a->

address=p1->

address=(p1->

address)+(a->

structidle*init3(structidle*head,structjob*p)//最差

if(p0==NULL)

"

if(p0->

else

elseif(p0->

structallocate*reallocate(structallocate*head,structjob*p)//重置已分配表

structallocate*p0,*p1,*p2;

//*p3,*p4;

//structidle*b;

p0=(structallocate*)malloc(LEN3);

p1=(structallocate*)malloc(LEN3);

if(head==NULL)

name=a->

name;

size=a->

head=p0;

Else

p1->

address=a->

p2=head;

while(p2->

p2=p2->

}p2->

next=p1;

structallocate*del(structallocate*head,structjob*p)//删除指定的作业

structjob*p1;

structallocate*p2,*p3;

p2=head;

p1=p;

while((p1->

name!

=p2->

name)&

(p2->

=NULL))

p3=p2;

p2=p2->

if(p1->

name==p2->

name)

if(p2==head)

head=p2->

else

p3->

next=p2->

structjob*delejob(structallocate*head)

structallocate*p2;

intnum;

p1=(structjob*)malloc(LEN1);

请输入要删除的作业的名称\n"

%d"

num);

while((num!

}

if(num==p2->

name=p2->

size=p2->

address=p2->

return(p1);

structidle*unite(structjob*p,structidle*head)//合并相邻内存空间

structidle*p1,*p2,*p3;

structjob*m;

m=p;

p1=head;

p3=(structidle*)malloc(LEN2);

address<

m->

address)&

(p1->

p2=p1;

p1=p1->

if(m->

address)

if(head==p1)

size=m->

address=m->

if((p1->

address-p3->

address)==(p3->

{

p1->

address=p3->

size=p3->

size+p1->

}

head=p3;

p3->

if((p3->

address-p2->

address)==(p2->

{

p2->

size=p1->

size+p2->

next=p1->

}

else

else

size+p3->

p3->

next=p3;

p3->

if((p3->

address-p1->

address)==(p1->

p1->

voidprint(structidle*h1,structallocate*h2)

structidle*m1;

structallocate*n1;

m1=h1;

n1=h2;

if(m1==NULL)

空闲表为空!

while(m1!

printf("

空闲单元地址为%d,其大小为%d\n"

m1->

address,m1->

m1=m1->

if(n1==NULL)

已分配表为空!

while(n1!

已分配单元地址为%d,其大小为%d,其名称为%d\n"

n1->

address,n1->

size,n1->

name);

n1=n1->

voidFF(void)

structjob*p,*q;

inty=1;

intn=0;

inta=1;

intc;

p1=creatidle();

p2=creatallocate();

初始情况为:

print(p1,p2);

while(a==y)

请输入要进行的操作:

1.建立作业2.删除作业3.结束操作\n"

scanf("

c);

switch(c)

case1:

p=creatjob();

p1=init1(p1,p);

p2=reallocate(p2,p);

print(p1,p2);

break;

case2:

q=delejob(p2);

p2=del(p2,q);

//p2=reallocate(p2,q);

p1=unite(q,p1);

case3:

y=0;

voidBF(void)

p1=init2(p1,p);

voidWF(void)

p1=init3(p1,p);

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

当前位置:首页 > 医药卫生 > 基础医学

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2