2022年操作系统内存管理代码 2.pdf
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_05.gif)
《2022年操作系统内存管理代码 2.pdf》由会员分享,可在线阅读,更多相关《2022年操作系统内存管理代码 2.pdf(8页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、程序代码:#include#include#define MAXMSIZE 99 using namespace std;struct Node int startAddress;char name;int size;int endAddress;struct Node*prior;struct Node*next;struct Blocklist Node*head;Blocklist*freelist=new Blocklist;Blocklist*busylist=new Blocklist;void initial();void allocateBlock();void print()
2、;void reclaimBlock();void main()int slct;initial();print();coutselect allocetion(1)or reclaim(2):slct;switch(slct)case 1:allocateBlock();print();break;case 2:reclaimBlock();print();break;default:break;名师资料总结-精品资料欢迎下载-名师精心整理-第 1 页,共 8 页 -void allocateBlock()/分配分区 char nm;int strtadd,sz;Node*ftemp,*de
3、lt,*btemp;ftemp=freelist-head;btemp=busylist-head;coutplseae input a new block information:endl;cout-name-startAdd-size-nmstrtaddsz;bool bfinish=false;bool ffinish=false;Node*p=new Node;p-name=nm;p-startAddress=strtadd;p-size=sz;p-endAddress=p-startAddress+p-size-1;if(busylist-head=NULL&bfinish=fals
4、e)/分配使用链表的头结点btemp=p;btemp-prior=NULL;btemp-next=NULL;bfinish=true;busylist-head=btemp;else while(btemp!=NULL&bfinish=false)/查找使用链表的可分配点 if(btemp-endAddress startAddress&btemp-next=NULL)/加入使用链表链尾p-next=NULL;p-prior=btemp;btemp-next=p;bfinish=true;else if(btemp-endAddress startAddress&btemp-next-star
5、tAddress p-endAddress)/加入使用链表链中p-next=btemp-next;p-prior=btemp;btemp-next-prior=p;btemp-next=p;bfinish=true;名师资料总结-精品资料欢迎下载-名师精心整理-第 2 页,共 8 页 -else if(btemp-prior=NULL&btemp-startAddress p-endAddress&p-startAddress=0)/加入使用链表链头p-next=btemp;p-prior=NULL;btemp-prior=p;busylist-head=p;bfinish=true;btem
6、p=btemp-next;while(ftemp!=NULL&ffinish=false&bfinish=true)/增加结点修改空闲链表 if(ftemp-startAddress startAddress&ftemp-endAddress=p-endAddress)Node*q=new Node;q-startAddress=p-endAddress+1;q-endAddress=ftemp-endAddress;q-size=q-endAddress-q-startAddress+1;q-prior=ftemp;q-next=ftemp-next;ftemp-endAddress=p-s
7、tartAddress-1;ftemp-size=ftemp-endAddress-ftemp-startAddress+1;ftemp-next=q;ffinish=true;ftemp=ftemp-next;if(ffinish=true)/查找需要删除的结点并删除之 ftemp=freelist-head;while(ftemp!=NULL)if(ftemp-size=0)if(ftemp=freelist-head)freelist-head=ftemp-next;else 名师资料总结-精品资料欢迎下载-名师精心整理-第 3 页,共 8 页 -ftemp-prior-next=fte
8、mp-next;ftemp-next-prior=ftemp-prior;delt=ftemp;ftemp=ftemp-next;delete delt;else ftemp=ftemp-next;coutit has been allocated!endl;else coutit cannot allocate!endl;void initial()/初始分配 coutinitial.startAddress=0;fl-endAddress=MAXMSIZE;fl-size=fl-endAddress-fl-startAddress+1;fl-prior=NULL;fl-next=NULL;
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 2022年操作系统内存管理代码 2022 操作系统 内存 管理 代码
![提示](https://www.taowenge.com/images/bang_tan.gif)
限制150内