




版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、大#跖大殍實驗報告學院系名稱:計算機與通信工程學院姓名劉俊杰學號20215542專業(yè)信息與計算科學班級2021級1班實驗工程實驗二:存儲器的分配與回收算法實現(xiàn)課程名稱操作系統(tǒng)課程代碼0668036實驗時間2021-11-273-4節(jié)2021-11-297-8節(jié)2021-12-43-4節(jié)2021-12-67-8節(jié)實驗地點主校區(qū)7-215批改意見成績教師簽字:實驗內容:1 .本實驗是模擬操作系統(tǒng)的主存分配,運用可變分區(qū)的存儲治理算法設計主存分配和回收程序,并不實際啟動裝入作業(yè).2 .采用最先適應法、最正確適應法、最壞適應法分配主存空間.3 .身-個新作業(yè)要求裝入主存時,必須查空閑區(qū)表,從中找出一個
2、足夠大的空閑區(qū).假設找到的空閑區(qū)大于作業(yè)需要量,這是應把它分成二局部,一局部為占用區(qū),加一局部又成才-個空閑區(qū).4 .身-個作業(yè)撤離時,歸還的區(qū)域如果與其他空閑區(qū)相鄰,那么應合并成一個較大的空閑區(qū),登在空閑區(qū)表中.5 .設計的模擬系統(tǒng)中,進程數(shù)不小于5,進程調度方式可以采用實驗一中的任何一種.6 .運行所設計的程序,輸出有關數(shù)據結構表項的變化和內存的當前狀態(tài).實驗要求:1 .詳細描述實驗設計思想、程序結構及各模塊設計思路;2 .詳細描述程序所用數(shù)據結構及算法;3 .明確給出測試用例和實驗結果;4 .為增加程序可讀性,在程序中進行適當注釋說明;5 .認真進行實驗總結,包括:設計中遇到的問題、解決
3、方法與收獲等;6 .實驗報告撰寫要求結構清楚、描述準確邏輯性強;7 .實驗過程中,同學之間可以進行討論互相提升,但絕對禁止抄襲.代碼實現(xiàn):#include#include#defineNULL0#defineLEN1sizeof(structjob)/作業(yè)大小#defineLEN2sizeof(structidle)/空閑區(qū)單元大小#defineLEN3sizeof(structallocate)/已分配區(qū)單元大小intSPACE=100;定義內存空間大小intORIGI=1;/定義內存起始地址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(請輸入要運行的作業(yè)的名稱與大?。簄);scanf(%d%d,&p-name,&p-size);return(p);structidle*init1(structidle*head,structjob*p)/首次適應算法分配內存(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(無法分配n);return(head);structidle*init2(structidle*head,structjob*p)/最優(yōu)(structidle*p0,*p1;structjob*a;a=p;p0=head;if(p0=NULL)(printf(無法進行分配!n);while(p0-next!=NULL&p0-siz
7、esize)(p0=p0-next;if(p0-sizea-size)(p1=p0;p0=p0-next;)else(printf(無法分配!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(無法進行分配!);)while(p0-next!=NULL&p0-sizesize)(p0=p0-next;)if(p0-sizea-size)(p1=p0;p0=p0-next;)else(printf(無法分配!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(請輸入要刪除的作業(yè)的名稱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,其名稱為%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(請輸入要進行的操作:1.建立彳業(yè)2.刪除作業(yè)3.結束操作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(請輸入要
18、進行的操作:1.建立彳業(yè)2.刪除作業(yè)3.結束操作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. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 起重機專業(yè)知識培訓課件
- 2025年度環(huán)保材料加工技術研發(fā)合同
- 二零二五年度個人公寓租賃管理協(xié)議
- 武漢2025年度商業(yè)地產租賃及品牌管理合同
- 二零二五年度早餐店加盟合作協(xié)議
- 二零二五年度農業(yè)科技公司技術員勞動合同終止及農業(yè)技術指導合同
- 二零二五年度企業(yè)員工虛擬股權激勵與員工權益保障合同
- 二零二五年度房屋租賃雙方租賃合同解除及違約賠償協(xié)議書
- 2025年度生態(tài)保護區(qū)房屋拆遷補償安置協(xié)議
- 2025年度旅游景區(qū)商鋪租賃及景區(qū)住宿服務合作合同
- 會計信息化題庫與答案
- “學-訓-評”一體化師范生實踐能力培養(yǎng)模式的探索與實踐
- 錢三強完整版本
- 糖尿病飲食指導護理
- 初一到初三英語單詞表2182個帶音標打印版
- 石油工程設計大賽采油單項組
- 急性淋巴細胞白血病護理查房
- 中建“大商務”管理實施方案
- 中國肥胖及代謝疾病外科治療指南(2024版)
- 2024年消防月全員消防安全知識培訓
- 《物聯(lián)網嵌入式技術》教學教案
評論
0/150
提交評論