




版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、暨南大學(xué)本科實(shí)驗(yàn)報(bào)告專用紙一, 實(shí)驗(yàn)?zāi)康?。了解?dòng)態(tài)分區(qū)分配方式中使用的數(shù)據(jù)結(jié)構(gòu)和分配算法,并進(jìn)一步加深對(duì)動(dòng)態(tài)扮區(qū)存儲(chǔ)管理方式及其實(shí)現(xiàn)過(guò)程的理解。二, 實(shí)驗(yàn)內(nèi)容。1分別實(shí)現(xiàn)首次適應(yīng)算法和最佳適應(yīng)算法的動(dòng)態(tài)分區(qū)分配過(guò)程和回收過(guò)程。其中,空閑分區(qū)通過(guò)空閑區(qū)鏈進(jìn)行管理;進(jìn)行內(nèi)存分配時(shí),系統(tǒng)優(yōu)先使用空閑區(qū)低端的空間。2、假設(shè)初試狀態(tài)下,可用的內(nèi)存空間為640KB,并有下列的請(qǐng)求序列:作業(yè)1申請(qǐng) 130KB作業(yè)2申請(qǐng) 60KB作業(yè)3申請(qǐng) 100KB作業(yè)2釋放 60KB作業(yè)4申請(qǐng) 200KB作業(yè)3釋放 100KB作業(yè)1釋放 130KB作業(yè)5申請(qǐng) 140KB作業(yè)6申請(qǐng) 60KB作業(yè)7申請(qǐng) 50KB作業(yè)6釋放
2、60KB3、每次分配和回收后顯示空閑內(nèi)存分區(qū)鏈情況。三, 實(shí)驗(yàn)源代碼。最佳適應(yīng)算法:#include"stdio.h"#include"stdlib.h"int i=1;/idtypedef struct memint start;int end;struct mem *next;mem;typedef struct workint id;int size;/memsizeint start;struct work *next;work; work* initwork(int size)work *head=(work *)mall
3、oc(sizeof(head);head->id=i;head->start=1;head->size=size;head->next=NULL;return head;work* insertwork(work *head,int start,int size)i+;work *pi,*pb;/pi is the insert one #pb is the pointpi=(work*)malloc(sizeof(work);pi->id=i;pi->start=start;pi->size=size;pi->next=NULL;if(head
4、=NULL)head=pi;head->next=NULL;pb=head;while(pb->next!=NULL)pb=pb->next;pb->next=pi;return head;mem *initmem(int size)mem *head=(mem*)malloc(sizeof(mem);head->start=1;head->end=640;head->next=NULL;return head;mem *insertmem(mem *head,int start,int size)mem *pi,*pb,*pf;int pbsize;
5、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->start<pb->start) &
6、#160; if(pb=head) head=pi;/頭節(jié)點(diǎn) pi->next=pb; else pf->next=pi;/其他位置 &
7、#160; pi->next=pb; else pb->next=pi; pi->next=NULL;/在表末插入 /合并相鄰的內(nèi)存 pf=pb=head;while(pb->next!=NULL)
8、 if(pf->end+2>pb->start) pf->end=pb->end; pf->next=pb->next; pf=pb; pb=pb->next;return head;int getstart(work*head,int size)work *pb;pb=
9、head;while(pb!=NULL) if(pb->size=size) return pb->start; pb=pb->next; return 0; int alloc(mem *head,int size)mem *pb;pb=head;int a;while(pb!=NULL) if(size<=(pb->end-pb->start+1)
10、 a=pb->start; pb->start=pb->start+size; return a; pb=pb->next; return 0; work*free1(work *head,int size)work *pb,*pf;while(head=NULL)printf(&q
11、uot;no this nod");goto end;pb=head;while(pb->size!=size&&pb->next!=NULL) pf=pb; pb=pb->next; if(pb->size=size) if(pb=head)head=pb->next; else pf->next=pb->next;
12、60; end:return head;void printw(work *head)work *pb;pb=head;while(pb!=NULL) printf("id start size->n"); printf("%d%7d%8dn",pb->id,pb->start,pb->size); pb=pb->next;void p
13、rintm(mem *head)mem *pb;pb=head;while(pb!=NULL) printf("start end->n"); printf("%d%9dn",pb->start,pb->end); pb=pb->next;void main() int wrec;/接收返回的地址int mrec;mem *mhead;mhead=initmem(640);work *whead;/1
14、; whead=initwork(130);wrec=alloc(mhead,130);/2 wrec=alloc(mhead,60); whead=insertwork(whead,wrec,60);/3wrec=alloc(mhead,100);whead=insertwork(whead,wrec,100);/4mrec=getstart(whead,60);whead=free1(whead,60); mhead=insertmem(mhead,mrec,60);/5w
15、rec=alloc(mhead,200);whead=insertwork(whead,wrec,200);/6 mrec=getstart(whead,100);whead=free1(whead,100);mhead=insertmem(mhead,mrec,100);/7mrec=getstart(whead,130);whead=free1(whead,130);mhead=insertmem(mhead,mrec,130);/8 wrec=alloc(mhead,140);whead=insertwork(whead,wrec,140)
16、;/9wrec=alloc(mhead,60);whead=insertwork(whead,wrec,60);/10wrec=alloc(mhead,50);whead=insertwork(whead,wrec,50);/11mrec=getstart(whead,60);whead=free1(whead,60);mhead=insertmem(mhead,mrec,60);printf("作業(yè)的鏈表n");printw(whead);printf("=n");printf("空閑分區(qū)鏈表n");printm(mhead);首次
17、適應(yīng)算法:#include "stdio.h" struct allocquery /* 定義請(qǐng)求序列結(jié)構(gòu)體*/ int num; int state; /* a表示申請(qǐng),f表示釋放 */ int length; ; struct allocquery allocq11; struct freequery /* 定義內(nèi)存分配隊(duì)列 */ int flag; /* IDNo. 0表示空閑,其他數(shù)值表示相應(yīng)作業(yè) */ int firstadd; /* 起始地址 */ int length; /* 占有長(zhǎng)度 */ ; struct freequery freeq11; /* 首次適
18、應(yīng)算法函數(shù)*/ void first_alg(struct allocquery allocqnow,int *ptotal,struct freequery *pfreeq); main() int i,j; FILE *fp; char *fname="c:a.txt" int Freetotal=1; fp=fopen(fname,"w+"); allocq0.num=1; allocq0.state='a' allocq0.length=130; allocq1.num=2; allocq1.state='a' a
19、llocq1.length=60; allocq2.num=3; allocq2.state='a' allocq2.length=100; allocq3.num=2; allocq3.state='f' allocq3.length=60; allocq4.num=4; allocq4.state='a' allocq4.length=200; allocq5.num=3; allocq5.state='f' allocq5.length=100; allocq6.num=1; allocq6.state='f'
20、; allocq6.length=130; allocq7.num=5; allocq7.state='a' allocq7.length=140; allocq8.num=6; allocq8.state='a' allocq8.length=60; allocq9.num=7; allocq9.state='a' allocq9.length=50; allocq10.num=6; allocq10.state='f' allocq10.length=60; freeq0.flag=0; freeq0.firstadd=0;
21、freeq0.length=640; for(i=0;i<11;i+) first_alg(allocqi,&Freetotal,freeq); fprintf(fp,"nTotal free blocks:%d ",Freetotal) ; fprintf(fp,"nIDNo. address length"); for(j=0;freeqj.length!=0;j+) fprintf(fp,"n%5d%10d%10d",freeqj.flag,freeqj.firstadd,freeqj.length); void
22、first_alg(struct allocquery allocqnow,int *ptotal,struct freequery *pfreeq) int i,j,num; int temp_num,temp_add,temp_length; struct freequery temp_f1,temp_f2; if (allocqnow.state='a') /* 表示申請(qǐng)空間 */ for (i=0;i<11;i+) if(pfreeqi.flag=0)&(pfreeqi.length>allocqnow.length) temp_num=pfreeq
23、i.flag; temp_add=pfreeqi.firstadd+allocqnow.length; temp_length=pfreeqi.length-allocqnow.length; pfreeqi.flag=allocqnow.num; pfreeqi.length=allocqnow.length; if (pfreeqi+1.length=0) pfreeqi+1.flag=temp_num; pfreeqi+1.firstadd=temp_add; pfreeqi+1.length=temp_length; else if (pfreeqi+1.firstadd!=temp_
24、add) temp_f1.flag=temp_num; temp_f1.firstadd=temp_add; temp_f1.length=temp_length; temp_f2=pfreeqi+1; for (j=i+1;pfreeqj.length!=0;j+) pfreeqj=temp_f1; temp_f1=temp_f2; temp_f2=pfreeqj+1; pfreeqj=temp_f1; break; else /* 釋放空間*/ for (i=0;i<11;i+) if (pfreeqi.flag=allocqnow.num) if (pfreeqi-1.flag=0)&(pfreeqi+1.flag=0)&(i>0) pfreeqi-1.length=pfree
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 餐飲行業(yè)廚師技能培訓(xùn)勞動(dòng)合同模板
- 海洋工程安裝工程保障險(xiǎn)合同
- 水產(chǎn)養(yǎng)殖場(chǎng)場(chǎng)地租賃與養(yǎng)殖服務(wù)合同
- 圖形推理面試題及答案
- 安全生產(chǎn)事故應(yīng)急管理與人員聘用合同
- 餐飲連鎖企業(yè)員工勞動(dòng)招聘與培訓(xùn)體系合同
- 汽車財(cái)務(wù)面試題及答案
- 水輪機(jī)考試題計(jì)算及答案
- 餐飲品牌加盟商權(quán)益保護(hù)合同
- 黨課黨員心理健康課件
- 新疆警察學(xué)院面試問(wèn)題及答案
- 小學(xué)三到六年級(jí)全冊(cè)單詞默寫(素材)-2023-2024學(xué)年譯林版(三起)小學(xué)英語(yǔ)
- 鐵嶺市高校畢業(yè)生“三支一扶”計(jì)劃招募筆試真題2022
- DL-T1474-2021交、直流系統(tǒng)用高壓聚合物絕緣子憎水性測(cè)量及評(píng)估方法
- 水利安全生產(chǎn)風(fēng)險(xiǎn)防控“六項(xiàng)機(jī)制”右江模式經(jīng)驗(yàn)分享
- 天然氣泄漏事故演練方案及評(píng)估
- 《養(yǎng)老機(jī)構(gòu)認(rèn)知障礙照護(hù)專區(qū)設(shè)置與服務(wù)規(guī)范》
- 婦科炎癥健康教育課件
- 兒科護(hù)理學(xué)(高職)全套教學(xué)課件
- 干眼門診建設(shè)計(jì)劃書(shū)
- MBR膜系統(tǒng)清洗方案
評(píng)論
0/150
提交評(píng)論