操作系统实验五.docx

操作系统实验五.docx

ID:51422151

大小:25.90 KB

页数:10页

时间:2020-03-24

操作系统实验五.docx_第1页
操作系统实验五.docx_第2页
操作系统实验五.docx_第3页
操作系统实验五.docx_第4页
操作系统实验五.docx_第5页
资源描述:

《操作系统实验五.docx》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库

1、暨南大学本科实验报告专用纸一,实验目的。了解动态分区分配方式中使用的数据结构和分配算法,并进一步加深对动态扮区存储管理方式及其实现过程的理解。二,实验内容。1分别实现首次适应算法和最佳适应算法的动态分区分配过程和回收过程。其中,空闲分区通过空闲区链进行管理;进行内存分配时,系统优先使用空闲区低端的空间。2、假设初试状态下,可用的内存空间为640KB,并有下列的请求序列:作业1申请130KB作业2申请60KB作业3申请100KB作业2释放60KB作业4申请200KB作业3释放100KB作业1释放130KB作业5申请140KB

2、作业6申请60KB作业7申请50KB作业6释放60KB3、每次分配和回收后显示空闲内存分区链情况。三,实验源代码。最佳适应算法:#include"stdio.h"#include"stdlib.h"inti=1;//idtypedefstructmem{intstart;intend;structmem*next;}mem;typedefstructwork{intid;intsize;//memsizeintstart;structwork*next;}work;  work*initwork(intsize){work

3、*head=(work*)malloc(sizeof(head));head->id=i;head->start=1;head->size=size;head->next=NULL;returnhead;}work*insertwork(work*head,intstart,intsize){i++;work*pi,*pb;//piistheinsertone##pbisthepointpi=(work*)malloc(sizeof(work));pi->id=i;pi->start=start;pi->size=size

4、;pi->next=NULL;if(head==NULL){head=pi;head->next=NULL;}pb=head;while(pb->next!=NULL){pb=pb->next;}pb->next=pi;returnhead;}mem*initmem(intsize){mem*head=(mem*)malloc(sizeof(mem));head->start=1;head->end=640;head->next=NULL;returnhead;}mem*insertmem(mem*head,intstar

5、t,intsize){mem*pi,*pb,*pf;intpbsize;pb=head;pbsize=pb->end-pb->start+1;pi=(mem*)malloc(sizeof(mem));pi->start=start;pi->end=size+start-1;if(pb==NULL){head=pi;pi->next=NULL;}else{  while(pi->start>pb->start&&pb->next!=NULL){pf=pb;pb=pb->next;}  if(pi->startsta

6、rt)  {   if(pb==head)   {         head=pi;//头节点    pi->next=pb;   }     else   {    pf->next=pi;//其他位置    pi->next=pb;       }      }  else  {   pb->next=pi;   pi->next=NULL;//在表末插入  }}//合并相邻的内存    pf=pb=head;while(pb->next!=NULL){  if(pf->end+2>pb->start)    {   

7、    pf->end=pb->end;    pf->next=pb->next;    }  pf=pb;  pb=pb->next;}returnhead;}intgetstart(work*head,intsize){work*pb;pb=head;while(pb!=NULL){  if(pb->size==size)  {   returnpb->start;  }  pb=pb->next;}    return0;}intalloc(mem*head,intsize){mem*pb;pb=head;inta

8、;while(pb!=NULL){  if(size<=(pb->end-pb->start+1))  {      a=pb->start;   pb->start=pb->start+size;     returna;  }  pb=pb->next;}    return0;}work*free

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。