欢迎来到天天文库
浏览记录
ID:38632270
大小:64.50 KB
页数:11页
时间:2019-06-16
《操作系统存储器管理源代码》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、动态分区分配模拟项目源代码#include#include#defineFree0#defineBusy1#defineOK1#defineERROR0#defineMAX_length1280typedefintStatus;typedefstructfreearea{intID;longsize;longaddress;intstate;}ElemType;typedefstructDuLNode//doublelinkedlist{ElemTypedata;structDuLN
2、ode*prior;structDuLNode*next;}DuLNode,*DuLinkList;DuLinkListblock_first;DuLinkListblock_last;Statusalloc(int);Statusfree(int);StatusFirst_fit(int,int);StatusBest_fit(int,int);voidshow();StatusInitblock();StatusInitblock(){block_first=(DuLinkList)malloc(sizeof(DuLNod
3、e));block_last=(DuLinkList)malloc(sizeof(DuLNode));block_first->prior=NULL;block_first->next=block_last;block_last->prior=block_first;block_last->next=NULL;block_last->data.address=0;block_last->data.size=MAX_length;block_last->data.ID=0;block_last->data.state=Free;
4、returnOK;}Statusalloc(intch){intID,request;cout<<"请输入作业(分区号):";cin>>ID;cout<<"请输入需要分配的主存大小(单位:KB):";cin>>request;if(request<0
5、
6、request==0){cout<<"分配大小不合适,请重试!"<7、败!"<data.ID=ID;temp->data.size=request;temp->data.state8、=Busy;DuLNode*p=block_first->next;while(p){if(p->data.state==Free&&p->data.size==request){p->data.state=Busy;p->data.ID=ID;returnOK;break;}if(p->data.state==Free&&p->data.size>request){temp->prior=p->prior;temp->next=p;temp->data.address=p->data.address;p->prior->ne9、xt=temp;p->prior=temp;p->data.address=temp->data.address+temp->data.size;p->data.size-=request;returnOK;break;}p=p->next;}returnERROR;}StatusBest_fit(intID,intrequest){intch;DuLinkListtemp=(DuLinkList)malloc(sizeof(DuLNode));temp->data.ID=ID;temp->data.size=request;10、temp->data.state=Busy;DuLNode*p=block_first->next;DuLNode*q=NULL;while(p){if(p->data.state==Free&&(p->data.size>request11、12、p->data.size==req
7、败!"<data.ID=ID;temp->data.size=request;temp->data.state
8、=Busy;DuLNode*p=block_first->next;while(p){if(p->data.state==Free&&p->data.size==request){p->data.state=Busy;p->data.ID=ID;returnOK;break;}if(p->data.state==Free&&p->data.size>request){temp->prior=p->prior;temp->next=p;temp->data.address=p->data.address;p->prior->ne
9、xt=temp;p->prior=temp;p->data.address=temp->data.address+temp->data.size;p->data.size-=request;returnOK;break;}p=p->next;}returnERROR;}StatusBest_fit(intID,intrequest){intch;DuLinkListtemp=(DuLinkList)malloc(sizeof(DuLNode));temp->data.ID=ID;temp->data.size=request;
10、temp->data.state=Busy;DuLNode*p=block_first->next;DuLNode*q=NULL;while(p){if(p->data.state==Free&&(p->data.size>request
11、
12、p->data.size==req
此文档下载收益归作者所有