




版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、精選優(yōu)質(zhì)文檔-傾情為你奉上暨南大學(xué)本科實(shí)驗(yàn)報(bào)告專(zhuān)用紙一, 實(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
2、申請(qǐng) 50KB作業(yè)6釋放 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
3、=(work *)malloc(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
4、=NULL;if(head=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,*p
5、f;int pbsize;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->
6、start) if(pb=head) head=pi;/頭節(jié)點(diǎn) pi->next=pb; else pf->next=pi;/其他位置
7、 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
9、)work *pb;pb=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
10、->start+1) 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=N
11、ULL)printf("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、160; 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-&g
13、t;next;void printm(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;/
14、1 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
15、,mrec,60);/5wrec=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(wh
16、ead,wrec,140);/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");pri
17、ntm(mhead);首次適應(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 fr
18、eeq11; /* 首次適應(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=
19、'a' allocq1.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.sta
20、te='f' 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
21、.firstadd=0; 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.l
22、ength); void 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) te
23、mp_num=pfreeqi.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.fi
24、rstadd!=temp_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=pfreeqi-1.l
溫馨提示
- 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ì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年工程管理與咨詢考試試題及答案
- 標(biāo)桿企業(yè)運(yùn)營(yíng)管控-現(xiàn)場(chǎng)施工管理標(biāo)準(zhǔn)化實(shí)施細(xì)則
- 2026高考2025屆江蘇省高品質(zhì)高三高考科研卷語(yǔ)文試題及參考答案
- 金融衍生品交易風(fēng)險(xiǎn)管理合同
- 醫(yī)院職工違反管理制度
- 廚房就餐衛(wèi)生管理制度
- 中醫(yī)項(xiàng)目介紹
- 小學(xué)考勤考核管理制度
- 商場(chǎng)餐飲樓層管理制度
- 公司外出審批管理制度
- 2022年小學(xué)生詩(shī)詞大賽參考題庫(kù)200題(含答案)
- 水泥廠工藝流程圖
- 提高腸鏡患者腸道準(zhǔn)備合格率課件
- 公司物品采購(gòu)申請(qǐng)單
- 《卓有成效的管理者》Word電子版電子版本
- 喪假證明模板
- 螺紋基本尺寸對(duì)照表
- T∕CIC 049-2021 水泥窯用固體替代燃料
- 集裝箱出口十聯(lián)單
- 工藝管理控制程序文件
- 重慶市中小學(xué)生健康體檢表
評(píng)論
0/150
提交評(píng)論