计算机操作系统内存分配实验源代码

计算机操作系统内存分配实验源代码

ID:39563624

大小:121.00 KB

页数:13页

时间:2019-07-06

计算机操作系统内存分配实验源代码_第1页
计算机操作系统内存分配实验源代码_第2页
计算机操作系统内存分配实验源代码_第3页
计算机操作系统内存分配实验源代码_第4页
计算机操作系统内存分配实验源代码_第5页
资源描述:

《计算机操作系统内存分配实验源代码》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库

1、#include#include#defineOK1//完成#defineERROR0//出错typedefintStatus;typedefstructfree_table//定义一个空闲区说明表结构{intnum;//分区序号longaddress;//起始地址longlength;//分区大小intstate;//分区状态}ElemType;typedefstructNode//线性表的双向链表存储结构{ElemTypedata;structNodeprior;//前趋指针structNodenext;//后继指针}No

2、de,LinkList;LinkListfirst;//头结点LinkListend;//尾结点intflag;//记录要删除的分区序号StatusInitblock()//开创带头结点的内存空间链表{first=(LinkList)malloc(sizeof(Node));end=(LinkList)malloc(sizeof(Node));first->prior=NULL;first->next=end;end->prior=first;end->next=NULL;end->data.num=1;end->data.address=40;end->data

3、.length=600;end->data.state=0;returnOK;}voidsort()//分区序号重新排序{Nodep=first->next,q;q=p->next;for(;p!=NULL;p=p->next){for(q=p->next;q;q=q->next){if(p->data.num>=q->data.num){q->data.num+=1;}}}}//显示主存分配情况voidshow(){intflag=0;//用来记录分区序号Nodep=first;p->data.num=0;p->data.address=0;p->data.le

4、ngth=40;p->data.state=1;sort();printf("tt》主存空间分配情况《");printf("");printf("分区序号t起始地址t分区大小t分区状态");while(p){printf("%dtt%dtt%d",p->data.num,p->data.address,p->data.length);if(p->data.state==0)printf("tt空闲");elseprintf("tt已分配");p=p->next;}printf("");}//

5、首次适应算法StatusFirst_fit(intrequest){//为申请作业开辟新空间且初始化Nodep=first->next;LinkListtemp=(LinkList)malloc(sizeof(Node));temp->data.length=request;temp->data.state=1;p->data.num=1;while(p){if((p->data.state==0)&&(p->data.length==request)){//有大小恰好合适的空闲块p->data.state=1;returnOK;break;}elseif((p-

6、>data.state==0)&&(p->data.length>request)){//有空闲块能满足需求且有剩余temp->prior=p->prior;temp->next=p;temp->data.address=p->data.address;temp->data.num=p->data.num;p->prior->next=temp;p->prior=temp;p->data.address=temp->data.address+temp->data.length;p->data.length-=request;p->data.num+=1;retur

7、nOK;break;}p=p->next;}returnERROR;}//最佳适应算法StatusBest_fit(intrequest){intch;//记录最小剩余空间Nodep=first;Nodeq=NULL;//记录最佳插入位置LinkListtemp=(LinkList)malloc(sizeof(Node));temp->data.length=request;temp->data.state=1;p->data.num=1;while(p)//初始化最小空间和最佳位置{if((p->data.state==0)&&(p->data.length>=

8、reque

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

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

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