實(shí)驗(yàn)二:存儲(chǔ)器的分配與回收算法實(shí)現(xiàn)_第1頁(yè)
實(shí)驗(yàn)二:存儲(chǔ)器的分配與回收算法實(shí)現(xiàn)_第2頁(yè)
實(shí)驗(yàn)二:存儲(chǔ)器的分配與回收算法實(shí)現(xiàn)_第3頁(yè)
實(shí)驗(yàn)二:存儲(chǔ)器的分配與回收算法實(shí)現(xiàn)_第4頁(yè)
實(shí)驗(yàn)二:存儲(chǔ)器的分配與回收算法實(shí)現(xiàn)_第5頁(yè)
已閱讀5頁(yè),還剩5頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、大#跖大殍實(shí)驗(yàn)報(bào)告學(xué)院系名稱(chēng):計(jì)算機(jī)與通信工程學(xué)院姓名劉俊杰學(xué)號(hào)20215542專(zhuān)業(yè)信息與計(jì)算科學(xué)班級(jí)2021級(jí)1班實(shí)驗(yàn)工程實(shí)驗(yàn)二:存儲(chǔ)器的分配與回收算法實(shí)現(xiàn)課程名稱(chēng)操作系統(tǒng)課程代碼0668036實(shí)驗(yàn)時(shí)間2021-11-273-4節(jié)2021-11-297-8節(jié)2021-12-43-4節(jié)2021-12-67-8節(jié)實(shí)驗(yàn)地點(diǎn)主校區(qū)7-215批改意見(jiàn)成績(jī)教師簽字:實(shí)驗(yàn)內(nèi)容:1 .本實(shí)驗(yàn)是模擬操作系統(tǒng)的主存分配,運(yùn)用可變分區(qū)的存儲(chǔ)治理算法設(shè)計(jì)主存分配和回收程序,并不實(shí)際啟動(dòng)裝入作業(yè).2 .采用最先適應(yīng)法、最正確適應(yīng)法、最壞適應(yīng)法分配主存空間.3 .身-個(gè)新作業(yè)要求裝入主存時(shí),必須查空閑區(qū)表,從中找出一個(gè)

2、足夠大的空閑區(qū).假設(shè)找到的空閑區(qū)大于作業(yè)需要量,這是應(yīng)把它分成二局部,一局部為占用區(qū),加一局部又成才-個(gè)空閑區(qū).4 .身-個(gè)作業(yè)撤離時(shí),歸還的區(qū)域如果與其他空閑區(qū)相鄰,那么應(yīng)合并成一個(gè)較大的空閑區(qū),登在空閑區(qū)表中.5 .設(shè)計(jì)的模擬系統(tǒng)中,進(jìn)程數(shù)不小于5,進(jìn)程調(diào)度方式可以采用實(shí)驗(yàn)一中的任何一種.6 .運(yùn)行所設(shè)計(jì)的程序,輸出有關(guān)數(shù)據(jù)結(jié)構(gòu)表項(xiàng)的變化和內(nèi)存的當(dāng)前狀態(tài).實(shí)驗(yàn)要求:1 .詳細(xì)描述實(shí)驗(yàn)設(shè)計(jì)思想、程序結(jié)構(gòu)及各模塊設(shè)計(jì)思路;2 .詳細(xì)描述程序所用數(shù)據(jù)結(jié)構(gòu)及算法;3 .明確給出測(cè)試用例和實(shí)驗(yàn)結(jié)果;4 .為增加程序可讀性,在程序中進(jìn)行適當(dāng)注釋說(shuō)明;5 .認(rèn)真進(jìn)行實(shí)驗(yàn)總結(jié),包括:設(shè)計(jì)中遇到的問(wèn)題、解決

3、方法與收獲等;6 .實(shí)驗(yàn)報(bào)告撰寫(xiě)要求結(jié)構(gòu)清楚、描述準(zhǔn)確邏輯性強(qiáng);7 .實(shí)驗(yàn)過(guò)程中,同學(xué)之間可以進(jìn)行討論互相提升,但絕對(duì)禁止抄襲.代碼實(shí)現(xiàn):#include#include#defineNULL0#defineLEN1sizeof(structjob)/作業(yè)大小#defineLEN2sizeof(structidle)/空閑區(qū)單元大小#defineLEN3sizeof(structallocate)/已分配區(qū)單元大小intSPACE=100;定義內(nèi)存空間大小intORIGI=1;/定義內(nèi)存起始地址structjob/定義作業(yè)intname;intsize;intaddress;structidl

4、e/定義空閑區(qū)intsize;intaddress;structidle*next;structallocate/定義已分配區(qū)intname;intsize;intaddress;structallocate*next;structidle*creatidle(void)/建立空閑表structidle*head;structidle*p1;p1=(structidle*)malloc(LEN2);p1-size=SPACE;p1-address=ORIGI;p1-next=NULL;head=p1;return(head);structallocate*creatallocate(void)

5、/建立已分配表structallocate*head;head=NULL;return(head);structjob*creatjob(void)/建立作業(yè)structjob*p;p=(structjob*)malloc(LEN1);printf(請(qǐng)輸入要運(yùn)行的作業(yè)的名稱(chēng)與大?。簄);scanf(%d%d,&p-name,&p-size);return(p);structidle*init1(structidle*head,structjob*p)/首次適應(yīng)算法分配內(nèi)存(structidle*p0,*p1;structjob*a;a=p;p0=head;p1=p0;while(p0-next

6、!=NULL&p0-sizesize)(p0=p0-next;if(p0-sizea-size)(p0-size=p0-size-a-size;a-address=p0-address;p0-address=p0-address+a-size;else(printf(無(wú)法分配n);return(head);structidle*init2(structidle*head,structjob*p)/最優(yōu)(structidle*p0,*p1;structjob*a;a=p;p0=head;if(p0=NULL)(printf(無(wú)法進(jìn)行分配!n);while(p0-next!=NULL&p0-siz

7、esize)(p0=p0-next;if(p0-sizea-size)(p1=p0;p0=p0-next;)else(printf(無(wú)法分配!n);)while(p0!=NULL)(if(p0-sizep1-size)(p0=p0-next;)elseif(p0-sizesize)&(p0-sizea-size)(p1=p0;p0=p0-next;)p1-size=(p1-size)-(a-size);a-address=p1-address;p1-address=(p1-address)+(a-size);return(head);)structidle*init3(structidle*h

8、ead,structjob*p)/最差(structidle*p0,*p1;structjob*a;a=p;p0=head;if(p0=NULL)(printf(無(wú)法進(jìn)行分配!);)while(p0-next!=NULL&p0-sizesize)(p0=p0-next;)if(p0-sizea-size)(p1=p0;p0=p0-next;)else(printf(無(wú)法分配!n);while(p0!=NULL)(if(p0-sizesize)(p0=p0-next;)elseif(p0-sizep1-size)(p1=p0;p0=p0-next;)p1-size=(p1-size)-(a-si

9、ze);a-address=p1-address;p1-address=(p1-address)+(a-size);return(head);)structallocate*reallocate(structallocate*head,structjob*p)/重置已分配表(structallocate*p0,*p1,*p2;/*p3,*p4;structjob*a;/structidle*b;a=p;p0=(structallocate*)malloc(LEN3);p1=(structallocate*)malloc(LEN3);if(head=NULL)(p0-name=a-name;p0

10、-size=a-size;p0-address=ORIGI;p0-next=NULL;head=p0;)Else(p1-name=a-name;p1-size=a-size;p1-address=a-address;p2=head;while(p2-next!=NULL)(p2=p2-next;p2-next=p1;p1-next=NULL;)return(head);)structallocate*del(structallocate*head,structjob*p)/刪除指定的作業(yè)(structjob*p1;structallocate*p2,*p3;p2=head;p1=p;while

11、(p1-name!=p2-name)&(p2-next!=NULL)(p3=p2;p2=p2-next;)if(p1-name=p2-name)(if(p2=head)head=p2-next;elsep3-next=p2-next;)return(head);)structjob*delejob(structallocate*head)(structjob*p1;structallocate*p2;intnum;p1=(structjob*)malloc(LEN1);printf(請(qǐng)輸入要?jiǎng)h除的作業(yè)的名稱(chēng)n);scanf(%d,&num);p2=head;while(num!=p2-name

12、)&(p2-next!=NULL)(p2=p2-next;)if(num=p2-name)(p1-name=p2-name;p1-size=p2-size;p1-address=p2-address;)return(p1);)structidle*unite(structjob*p,structidle*head)(structidle*p1,*p2,*p3;structjob*m;m=p;p1=head;p3=(structidle*)malloc(LEN2);while(p1-addressaddress)&(p1-next!=NULL)(p2=p1;p1=p1-next;if(m-add

13、ressaddress)(if(head=p1)(p3-size=m-size;p3-address=m-address;if(p1-address-p3-address)=(p3-size)(p1-address=p3-address;p1-size=p3-size+p1-size;else(head=p3;p3-next=p1;else(p3-size=m-size;p3-address=m-address;if(p1-address-p3-address)=(p3-size)(p1-address=p3-address;p1-size=p3-size+p1-size;if(p3-addr

14、ess-p2-address)=(p2-size)(p2-size=p1-size+p2-size;p2-next=p1-next;else(p2-next=p1;)else(if(p3-address-p2-address)=(p2-size)(p2-size=p2-size+p3-size;)else(p3-next=p1;p2-next=p3;)else(p3-size=m-size;p3-address=m-address;if(p3-address-p1-address)=(p1-size)(p1-size=p1-size+p3-size;)else(p1-next=p3;p3-ne

15、xt=NULL;)return(head);)voidprint(structidle*h1,structallocate*h2)(structidle*m1;structallocate*n1;m1=h1;n1=h2;if(m1=NULL)(printf(空閑表為空!n);)else(while(m1!=NULL)printf(空閑單元地址為d,其大小為%dn,m1-address,m1-size);m1=m1-next;)if(n1=NULL)printf(已分配表為空!n);)elsewhile(n1!=NULL)printf(已分配單元地址為d,其大小為d,其名稱(chēng)為%dn,n1-add

16、ress,n1-size,n1-name);n1=n1-next;)voidFF(void)structidle*p1;structallocate*p2;structjob*p,*q;inty=1;intn=0;inta=1;intc;p1=creatidle();p2=creatallocate();printf(初始情況為:n);print(p1,p2);while(a=y)printf(請(qǐng)輸入要進(jìn)行的操作:1.建立彳業(yè)2.刪除作業(yè)3.結(jié)束操作n);scanf(%d,&c);switch(c)case1:p=creatjob();p1=init1(p1,p);p2=reallocate(

17、p2,p);print(p1,p2);break;case 2:q=delejob(p2);p2=del(p2,q);p2=reallocate(p2,q);p1=unite(q,p1);print(p1,p2);break;case 3:y=0;break;)voidBF(void)structidle*p1;structallocate*p2;structjob*p,*q;inty=1;intn=0;inta=1;intc;p1=creatidle();p2=creatallocate();printf(初始情況為:n);print(p1,p2);while(a=y)printf(請(qǐng)輸入要

18、進(jìn)行的操作:1.建立彳業(yè)2.刪除作業(yè)3.結(jié)束操作n);scanf(%d,&c);switch(c)case 1:p=creatjob();p1=init2(p1,p);p2=reallocate(p2,p);print(p1,p2);break;case 2:q=delejob(p2);p2=del(p2,q);p2=reallocate(p2,q);p1=unite(q,p1);print(p1,p2);break;case 3:y=0;break;)voidWF(void)(structidle*p1;structallocate*p2;structjob*p,*q;inty=1;intn=0;inta=1;intc;p1=creatidle();p2=creatalloc

溫馨提示

  • 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ì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論