




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、實驗內(nèi)容:模擬操作系統(tǒng)的主存分配,運用可變分區(qū)的存儲管理算法設(shè)計主存分配和回收程序,并不實際啟動裝入作業(yè)。采用最先適應(yīng)法、最佳適應(yīng)法、最壞適應(yīng)法分配主存空間。當一個新作業(yè)要求裝入主存時,必須查空閑區(qū)表,從中找出一個足夠大的空閑區(qū)。若找到的空閑區(qū)大于作業(yè)需要量,這是應(yīng)把它分成二部分,一部分為占用區(qū),加一部分又成為一個空閑區(qū)。當一個作業(yè)撤離時,歸還的區(qū)域如果與其他空閑區(qū)相鄰,則應(yīng)合并成一個較大的空閑區(qū),登在空閑區(qū)表中。運行所設(shè)計的程序,輸出有關(guān)數(shù)據(jù)結(jié)構(gòu)表項的變化和內(nèi)存的當前狀態(tài)。實驗要求:詳細描述實驗設(shè)計思想、程序結(jié)構(gòu)及各模塊設(shè)計思路;詳細描述程序所用數(shù)據(jù)結(jié)構(gòu)及算法;明確給出測試用例和實驗結(jié)果;為
2、增加程序可讀性,在程序中進行適當注釋說明;認真進行實驗總結(jié),包括:設(shè)計中遇到的問題、解決方法與收獲等;實驗報告撰寫要求結(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)/首次適應(yīng)算法分配內(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. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 國際產(chǎn)品授權(quán)分銷合同
- 辦公家具采購合同一
- 商品買賣合同「樣本」
- 商業(yè)地產(chǎn)買賣合同模板范文
- 公司設(shè)立投資合作合同范本
- 礦山棄渣處理合同范本
- 消防及安全整改合同履行細則
- 校企合作合同新范本
- 土地使用權(quán)出讓合同及物業(yè)銷售細則
- 躉船結(jié)構(gòu)培訓課件
- 伐樹工程施工合同范本
- 數(shù)據(jù)挖掘(第2版)PPT全套完整教學課件
- 工程開工報告(5篇)
- 配電箱試驗項目
- 運動技能學習與控制課件第一章運動技能學習與控制概述
- 溫室大棚花卉苗圃采暖方案空氣源熱泵
- BEC商務(wù)英語高級考試歷年真題
- 初二地理中考復習備考策略與計劃
- (完整word版)省級溫室氣體清單編制指南
- GB/T 39399-2020北斗衛(wèi)星導航系統(tǒng)測量型接收機通用規(guī)范
- 黔2022-T122 磷石膏砂漿噴筑復合墻標準圖集 第1部分:輕鋼龍骨-磷石膏砂漿噴筑復合墻體
評論
0/150
提交評論