




版權(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)二 主存儲(chǔ)器空間的分配和回收1、 實(shí)驗(yàn)內(nèi)容主存儲(chǔ)器空間的分配和回收。2、 實(shí)驗(yàn)?zāi)康挠?jì)算機(jī)系統(tǒng)不僅要有足夠容量、存儲(chǔ)速度高、穩(wěn)定可靠的主存儲(chǔ)器,而且要能合理的分配和使用者且存儲(chǔ)空間。主存的分配和回收的實(shí)現(xiàn)是與主存儲(chǔ)器的管理方式有關(guān)的。本實(shí)驗(yàn)有助于了解在不同的存儲(chǔ)管理方式下,應(yīng)怎樣實(shí)現(xiàn)主存空間的分配和回收。3、 實(shí)驗(yàn)題目在可變分區(qū)管理方式下,采用最先適應(yīng)算法實(shí)現(xiàn)主存空間的分配和回收。4、 數(shù)據(jù)結(jié)構(gòu)struct Block /空閑鏈結(jié)構(gòu)體 string name; /作業(yè)名 int address; /分區(qū)首地址 int size; /分區(qū)大小 int state; /分區(qū)轉(zhuǎn)態(tài) struct B
2、lock *next; /前向指針 struct Block *front; /后向指針 ; 構(gòu)造一個(gè)空閑鏈struct Used /已分配分區(qū)結(jié)構(gòu)體 Block *usedArea; Used *next; ;分配分區(qū)結(jié)構(gòu)體void Allocate(string reqName,int reqSize) /分配函數(shù) Block *p=freeHead->front ; Used *r1,*r2;while(p!=NULL) if(reqSize<p->size) /如果請(qǐng)求的分區(qū)的大小小于一個(gè)空閑分區(qū)的大小 Used *temp=new Used; temp->us
3、edArea =p; Block *q=new Block; 1 / 7 *q=*p; temp->usedArea ->name =reqName; temp->usedArea ->size =reqSize; temp->usedArea ->front =q; temp->usedArea ->state =1; q->size =q->size -reqSize; q->address =q->address + reqSize; q ->next->front=q; if(q ->front!
4、=NULL) q ->front->next=q; r1=usedHead; r2=usedHead->next; while(r2!=NULL&&r2->usedArea->address<temp->usedArea->address) r1=r2;r2=r2->next; r1->next=temp; temp->next=r2; break; else if(reqSize=p->size)/如果請(qǐng)求的分區(qū)的大小等于一個(gè)空閑分區(qū)的大小 Used *temp=new Used; temp->us
5、edArea =p; temp->usedArea ->name =reqName; temp->usedArea ->state =1; p->next->front =p->front ; if(p->front!=NULL) p->front ->next =p->next ; r1=usedHead; r2=usedHead->next; while(r2!=NULL&&r2->usedArea->address<temp->usedArea->address) r1=
6、r2;r2=r2->next; r1->next=temp; temp->next=r2; break; p=p->front;構(gòu)建一個(gè)鏈表,實(shí)現(xiàn)內(nèi)存分配。5、 源程序#include<iostream> #include<string> using namespace std; struct Block /空閑鏈結(jié)構(gòu)體 string name; /作業(yè)名 int address; /分區(qū)首地址 int size; /分區(qū)大小 int state; /分區(qū)轉(zhuǎn)態(tài) struct Block *next; /前向指針 struct Block *fro
7、nt; /后向指針 ; struct Used /已分配分區(qū)結(jié)構(gòu)體 Block *usedArea; Used *next; ; Block *freeHead; / 帶表頭附加節(jié)點(diǎn)的空閑鏈頭指針 Used *usedHead; /帶表頭附加結(jié)點(diǎn)的已分配分區(qū)頭指針 bool InitValue() /初始化函數(shù) cout<<"本程序設(shè)立的操作功能:1-申請(qǐng)資源 2-釋放資源 3-打印信息"<<endl; freeHead=new Block; freeHead->size=0; freeHead->next=NULL; freeHead-
8、>state=1; usedHead=new Used; Block *p=new Block; p->address=0; usedHead->usedArea=p; usedHead->next=NULL; Block *temp=new Block; cout<<"請(qǐng)先輸入主存大小(k):"<<endl; cin>>temp->size; temp->address=0; temp->state =0; temp->next=freeHead; temp->front=NULL;
9、 freeHead->front=temp; return true; void Display(Block *p,Used *q) /打印信息的函數(shù) cout<<"已分配分區(qū)信息(作業(yè),始址,大小):"<<endl; while(q!=NULL) cout<<q->usedArea->name<<','<<q->usedArea->address<<','<<q->usedArea->size<<endl
10、; q=q->next; cout<<"空閑鏈分區(qū)信息(始址,大小):"<<endl; while(p!=NULL) cout<<p->address<<',' cout<<p->size<<endl; p=p->front; void Allocate(string reqName,int reqSize) /分配函數(shù) Block *p=freeHead->front ; Used *r1,*r2; while(p!=NULL) if(reqSize<
11、;p->size) /如果請(qǐng)求的分區(qū)的大小小于一個(gè)空閑分區(qū)的大小 Used *temp=new Used; temp->usedArea =p; Block *q=new Block; *q=*p; temp->usedArea ->name =reqName; temp->usedArea ->size =reqSize; temp->usedArea ->front =q; temp->usedArea ->state =1; q->size =q->size -reqSize; q->address =q-&g
12、t;address + reqSize; q ->next->front=q; if(q ->front!=NULL) q ->front->next=q; r1=usedHead; r2=usedHead->next; while(r2!=NULL&&r2->usedArea->address<temp->usedArea->address) r1=r2;r2=r2->next; r1->next=temp; temp->next=r2; break; else if(reqSize=p-&g
13、t;size)/如果請(qǐng)求的分區(qū)的大小等于一個(gè)空閑分區(qū)的大小 Used *temp=new Used; temp->usedArea =p; temp->usedArea ->name =reqName; temp->usedArea ->state =1; p->next->front =p->front ; if(p->front!=NULL) p->front ->next =p->next ; r1=usedHead; r2=usedHead->next; while(r2!=NULL&&r2-
14、>usedArea->address<temp->usedArea->address) r1=r2;r2=r2->next; r1->next=temp; temp->next=r2; break; p=p->front; if(p=NULL) cout<<"資源不足 請(qǐng)等待"<<endl; void Recycle(string freeName) /回收分區(qū)的函數(shù) Used *p=usedHead->next,*r=usedHead; Block *q; while(p!=NULL) i
15、f(p->usedArea->name=freeName)/找到同名的作業(yè)后,再分四種情況討論 q=p->usedArea; int flag1=1,flag2=1; Block *p1=freeHead->front; Block *pfront,*pnext; while(p1->address<q->address) if(p1->address+p1->size=q->address)flag1=0;pnext=p1; p1=p1->front; if(q->address+q->size=p1->ad
16、dress) flag2=0;pfront=p1; if(flag1=0) if(flag2=0) pnext->front =pfront->front; pnext->size=pnext->size + q->size + pfront->size; if(pfront->front!=NULL) pfront ->front ->next=pnext; r->next =p->next; else pnext ->size +=q->size;r->next =p->next ; else if(
17、flag2 =0) pfront ->address -=q->size; pfront ->size +=q->size ; r->next =p->next ; else Block *temp=freeHead; while(temp->address <=q->address )temp=temp->front; q->front =temp; q->next =temp->next ; q->next->front =q; temp->next =q; q->state =0; r->next =p->next ; break; r=p; p=p->next ; int main() InitValue(); int operate;/操作符1-申請(qǐng)資源 2-釋放資源 3-打印信息 string name; int size; while(1) cout<<"請(qǐng)選擇操作功能"<<endl; cin>>operate; if(operate=1) cout<<&
溫馨提示
- 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年中國(guó)滋潤(rùn)嫩膚沐浴露市場(chǎng)調(diào)查研究報(bào)告
- 2025年中國(guó)松仁肚市場(chǎng)調(diào)查研究報(bào)告
- 2025年中國(guó)普朗貝樂(lè)噴劑市場(chǎng)調(diào)查研究報(bào)告
- 2025年中國(guó)抽油桿防脫器市場(chǎng)調(diào)查研究報(bào)告
- 2025年中國(guó)天平衡器市場(chǎng)調(diào)查研究報(bào)告
- 2025年中國(guó)多功能半自動(dòng)生化分析儀市場(chǎng)調(diào)查研究報(bào)告
- 2025年中國(guó)去痛片市場(chǎng)調(diào)查研究報(bào)告
- 小班開(kāi)學(xué)第一課教育教案
- 租售郊區(qū)小院合同協(xié)議
- 土石方中介費(fèi)合同協(xié)議
- 北京市西城區(qū)2025年中考一模物理試題(含答案)
- 2025年小學(xué)勞動(dòng)技能大賽實(shí)施方案-‘勞’以展風(fēng)采‘動(dòng)’手創(chuàng)未來(lái)
- 2025-2030中國(guó)外資銀行行業(yè)市場(chǎng)深度調(diào)研及競(jìng)爭(zhēng)格局與發(fā)展策略研究報(bào)告
- 2025北京豐臺(tái)高三一?;瘜W(xué)試題及答案
- 石油天然氣(海洋石油)工程AI智能應(yīng)用行業(yè)深度調(diào)研及發(fā)展戰(zhàn)略咨詢報(bào)告
- 2024年7月國(guó)家開(kāi)放大學(xué)專本科《法律文書》期末紙質(zhì)考試試題及答案
- 課件圍術(shù)期下肢深靜脈血栓的預(yù)防與護(hù)理
- 2013年7月國(guó)家開(kāi)放大學(xué)專本科《法律文書》期末紙質(zhì)考試試題及答案
- 《現(xiàn)代教育技術(shù)》教學(xué)設(shè)計(jì)公開(kāi)課教案教學(xué)設(shè)計(jì)課件資料
- 人教版高中物理選擇性必修第三冊(cè)期末檢測(cè)試卷
- 山東鐵投集團(tuán)筆試
評(píng)論
0/150
提交評(píng)論