版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領
文檔簡介
1、實驗內(nèi)容:模擬操作系統(tǒng)的主存分配,運用可變分區(qū)的存儲管理算法設計主存分配和回收程序,并不實際啟動裝入作業(yè)。采用最先適應法、最佳適應法、最壞適應法分配主存空間。當一個新作業(yè)要求裝入主存時,必須查空閑區(qū)表,從中找出一個足夠大的空閑區(qū)。若找到的空閑區(qū)大于作業(yè)需要量,這是應把它分成二部分,一部分為占用區(qū),加一部分又成為一個空閑區(qū)。當一個作業(yè)撤離時,歸還的區(qū)域如果與其他空閑區(qū)相鄰,則應合并成一個較大的空閑區(qū),登在空閑區(qū)表中。運行所設計的程序,輸出有關數(shù)據(jù)結(jié)構(gòu)表項的變化和內(nèi)存的當前狀態(tài)。實驗要求:詳細描述實驗設計思想、程序結(jié)構(gòu)及各模塊設計思路;詳細描述程序所用數(shù)據(jù)結(jié)構(gòu)及算法;明確給出測試用例和實驗結(jié)果;為
2、增加程序可讀性,在程序中進行適當注釋說明;認真進行實驗總結(jié),包括:設計中遇到的問題、解決方法與收獲等;實驗報告撰寫要求結(jié)構(gòu)清晰、描述準確邏輯性強;【實驗過程記錄(源程序、測試用例、測試結(jié)果及心得體會等)】#include<stdio.h>#include<malloc.h>#define NULL 0#define LEN1 sizeof(struct job)/作業(yè)大小#define LEN2 sizeof(struct idle)/空閑區(qū)單元大小#define LEN3 sizeof(struct allocate)/已分配區(qū)單元大小int SPACE=100;/定
3、義內(nèi)存空間大小int ORIGI=1;/定義內(nèi)存起始地址struct job/定義作業(yè)int name;int size;int address;struct idle/定義空閑區(qū)int size;int address;struct idle *next;struct allocate/定義已分配區(qū)int name;int size;int address;struct allocate *next;struct idle *creatidle(void)/建立空閑表struct idle *head;struct idle *p1;p1=(struct idle*)malloc(LEN2)
4、;p1->size=SPACE;p1->address=ORIGI;p1->next=NULL;head=p1;return(head);struct allocate *creatallocate(void)/建立已分配表struct allocate *head;head=NULL;return(head);struct job *creatjob(void)/建立作業(yè)struct job *p;p=(struct job*)malloc(LEN1);printf("請輸入要運行的作業(yè)的名稱與大小:n");scanf("%d%d",
5、&p->name,&p->size);return(p);struct idle *init1(struct idle *head,struct job *p)/首次適應算法分配內(nèi)存struct idle *p0,*p1;struct job *a;a=p;p0=head; p1=p0;while(p0->next!=NULL&&p0->size<a->size)p0=p0->next;if(p0->size>a->size)p0->size=p0->size-a->size;a-&g
6、t;address=p0->address;p0->address=p0->address+a->size;elseprintf("無法分配n");return(head);struct idle *init2(struct idle *head,struct job *p)/最優(yōu)struct idle *p0,*p1;struct job *a;a=p;p0=head; if(p0=NULL) printf("無法進行分配!n");while(p0->next!=NULL&&p0->size<a
7、->size)p0=p0->next; if(p0->size>a->size) p1=p0; p0=p0->next;else printf("無法分配!n");while(p0!=NULL)if(p0->size>p1->size)p0=p0->next;else if(p0->size<p1->size)&&(p0->size>a->size)p1=p0;p0=p0->next;p1->size=(p1->size)-(a->size
8、);a->address=p1->address;p1->address=(p1->address)+(a->size);return(head);struct idle *init3(struct idle *head,struct job *p)/最差struct idle *p0,*p1;struct job *a;a=p;p0=head; if(p0=NULL)printf("無法進行分配!");while(p0->next!=NULL&&p0->size<a->size)p0=p0->ne
9、xt;if(p0->size>a->size) p1=p0; p0=p0->next;elseprintf("無法分配!n");while(p0!=NULL) if(p0->size<p1->size)p0=p0->next;else if(p0->size>p1->size)p1=p0;p0=p0->next;p1->size=(p1->size)-(a->size);a->address=p1->address;p1->address=(p1->addres
10、s)+(a->size);return(head);struct allocate *reallocate(struct allocate *head,struct job *p)/重置已分配表struct allocate *p0,*p1,*p2;/*p3,*p4;struct job *a;/struct idle *b;a=p;p0=(struct allocate*)malloc(LEN3);p1=(struct allocate*)malloc(LEN3);if(head=NULL)p0->name=a->name;p0->size=a->size;p0
11、->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);struct allocate *del(struct allocate *head,struct job *p)/刪除指定的作業(yè)struct job *p1;st
12、ruct allocate *p2,*p3;p2=head;p1=p;while(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);struct job *delejob(struct allocate *head)struct job *p1;struct allocate *p2;int num;p1=
13、(struct job*)malloc(LEN1);printf("請輸入要刪除的作業(yè)的名稱n");scanf("%d",&num);p2=head; while(num!=p2->name)&&(p2->next!=NULL)p2=p2->next; if(num=p2->name)p1->name=p2->name;p1->size=p2->size;p1->address=p2->address;return(p1);struct idle *unite(struc
14、t job *p,struct idle *head)/合并相鄰內(nèi)存空間struct idle *p1,*p2,*p3;struct job *m;m=p;p1=head;p3=(struct idle*)malloc(LEN2);while(p1->address<m->address)&&(p1->next!=NULL)p2=p1;p1=p1->next;if(m->address<p1->address)if(head=p1)p3->size=m->size;p3->address=m->addres
15、s;if(p1->address-p3->address)=(p3->size)p1->address=p3->address;p1->size=p3->size+p1->size; elsehead=p3;p3->next=p1;elsep3->size=m->size;p3->address=m->address;if(p1->address-p3->address)=(p3->size)p1->address=p3->address;p1->size=p3->size+
16、p1->size;if(p3->address-p2->address)=(p2->size)p2->size=p1->size+p2->size;p2->next=p1->next;elsep2->next=p1;elseif(p3->address-p2->address)=(p2->size)p2->size=p2->size+p3->size;elsep3->next=p1;p2->next=p3;elsep3->size=m->size;p3->address
17、=m->address;if(p3->address-p1->address)=(p1->size)p1->size=p1->size+p3->size; elsep1->next=p3;p3->next=NULL;return(head);void print(struct idle *h1,struct allocate *h2)struct idle *m1;struct allocate *n1;m1=h1;n1=h2;if(m1=NULL)printf("空閑表為空!n");elsewhile(m1!=NULL
18、)printf("空閑單元地址為%d,其大小為%dn",m1->address,m1->size);m1=m1->next;if(n1=NULL)printf("已分配表為空!n");elsewhile(n1!=NULL)printf("已分配單元地址為%d,其大小為%d,其名稱為%dn",n1->address,n1->size,n1->name);n1=n1->next; void FF(void)struct idle *p1;struct allocate *p2;struct job
19、 *p,*q;int y=1;int n=0;int a=1;int c;p1=creatidle();p2=creatallocate();printf("初始情況為:n");print(p1,p2);while(a=y)printf("請輸入要進行的操作:1.建立作業(yè) 2.刪除作業(yè) 3.結(jié)束操作n");scanf("%d",&c);switch(c)case 1:p=creatjob();p1=init1(p1,p);p2=reallocate(p2,p);print(p1,p2);break;case 2: q=dele
20、job(p2);p2=del(p2,q);/p2=reallocate(p2,q);p1=unite(q,p1);print(p1,p2);break;case 3:y=0;break;void BF(void)struct idle *p1;struct allocate *p2;struct job *p,*q;int y=1;int n=0;int a=1;int c;p1=creatidle();p2=creatallocate();printf("初始情況為:n");print(p1,p2);while(a=y)printf("請輸入要進行的操作:1.建立作業(yè) 2.刪除作業(yè) 3.結(jié)束操作n");scanf("%d",&c);switch(c)case
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025版施工隊中途退場預防措施及違約責任協(xié)議3篇
- 2025年湖南省懷化靖州苗族侗族自治縣自來水公司招聘筆試參考題庫附帶答案詳解
- 2025年銷售員聘用協(xié)議書含客戶關系維護服務2篇
- 2025年度新型智能公寓租賃合同范本4篇
- 2025版安防產(chǎn)品銷售代理居間服務合同范本
- 2025年度個人租車保險及救援服務合作協(xié)議4篇
- 2025年全球及中國半導體光刻模擬器行業(yè)頭部企業(yè)市場占有率及排名調(diào)研報告
- 2025-2030全球心包穿刺套件行業(yè)調(diào)研及趨勢分析報告
- 2025年全球及中國光熱液壓系統(tǒng)行業(yè)頭部企業(yè)市場占有率及排名調(diào)研報告
- 2025年鋼構(gòu)工程裝配式建筑合同樣本2篇
- 湖南財政經(jīng)濟學院專升本管理學真題
- 2024年湖南商務職業(yè)技術學院單招職業(yè)適應性測試題庫帶答案
- 全國身份證前六位、區(qū)號、郵編-編碼大全
- 2024-2025學年福建省廈門市第一中學高一(上)適應性訓練物理試卷(10月)(含答案)
- 2024年全國各地中考試題分類匯編:作文題目
- 《糖拌西紅柿 》 教案()
- 彈性力學數(shù)值方法:解析法:彈性力學中的變分原理
- 《零售學第二版教學》課件
- 廣東省珠海市香洲區(qū)2023-2024學年四年級下學期期末數(shù)學試卷
- 房地產(chǎn)行業(yè)職業(yè)生涯規(guī)劃
- 江蘇省建筑與裝飾工程計價定額(2014)電子表格版
評論
0/150
提交評論