




下載本文檔
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、實(shí)驗(yàn)四內(nèi)存塊的申請(qǐng)與釋放實(shí)驗(yàn)?zāi)康恼莆諆?nèi)存動(dòng)態(tài)分區(qū)的實(shí)現(xiàn)方法。進(jìn)一步掌握內(nèi)存塊的分配策略。掌握內(nèi)存塊申請(qǐng)與釋放的算法與實(shí)現(xiàn)。實(shí)驗(yàn)內(nèi)容寫一個(gè)程序,模擬實(shí)現(xiàn)內(nèi)存的動(dòng)態(tài)分區(qū)分配算法。假設(shè)內(nèi)存大小為100K。分別使用首次適應(yīng)算法、最佳適應(yīng)算法分配內(nèi)存空間。實(shí)現(xiàn)對(duì)內(nèi)存空間的釋放。顯示內(nèi)存分配情況。實(shí)驗(yàn)環(huán)境本實(shí)驗(yàn)可以在Turbo C環(huán)境下實(shí)現(xiàn)。四.實(shí)驗(yàn)程序及分析/*進(jìn)入程序后可以根據(jù)菜單項(xiàng)進(jìn)入不同的模塊*/*1.使用首次適應(yīng)算法分配空間*/*2.使用最佳適應(yīng)算法分配空間*/*3.釋放一塊空間*/*4.顯示內(nèi)存分配情況*/*5.退出系統(tǒng)*/*/#include #include #include #inclu
2、de #define MEMSIZE 100/* 定義內(nèi)存大小為 100*/#define MINSIZE 2/*分配時(shí)如果剩余值小于此值則不再分割*/typedef struct MemoryInformation /*空間分區(qū)表結(jié)構(gòu) */int start;起始地址*/int size;大小*/char info;狀/態(tài):f空閑(FREE); u占用(USED);e表結(jié)束(END) */ MEMINFO;MEMINFO MemListMEMSIZE; void Display();/*/*函數(shù)名:InitAll()*/*/*功 能:初始化所有變量。/*/void InitAll() (in
3、t i;MEMINFO temp=0,0,e;for(i=0;iMEMSIZE;i+)MemListi = temp ;MemList0.start= 0;MemList0.size = MEMSIZE;MemL = f; TOC o 1-5 h z /*/*函數(shù)名:FirstFit_new()*/*功 能:使用首次適應(yīng)算法分配內(nèi)存*/*/void FirstFit_new() int i,j,size;char temp10;printf(How many MEMORY requir?);gets(temp); size=atoi(temp); for(i=0;i= siz
4、e & MemL = f) if(MemListi.size - size i;j-) MemListj+1 = MemListj; MemListi+1.start=MemListi.start + size; MemListi+1.size =MemListi.size - size; MemListi+1.info =f; MemListi.size=size; MemL=u ; break; if(i=MEMSIZE-1 | MemL = e) printf(NOT Enough Memory!n); getch(); Displa
5、y(); /*/*函數(shù)名:BestFit_new()/*功 能:使用最佳適應(yīng)算法分配內(nèi)存*/ /*/void BestFit_new() ( int i,j,k,flag,size; char temp10; printf(How many MEMORY requir?);gets(temp); size=atoi(temp); j=0; flag=0; k=MEMSIZE;for(i=0;i= size & MemL = f) ( flag=1; if(MemListi.size k) (k=MemListi.size; j=i; i=j; if(flag=0) ( pri
6、ntf(NOT Enough Memory!n); getch(); else if(MemListi.size - size i;j-) ( MemListj+1 = MemListj; MemListi+1.start=MemListi.start + size; MemListi+1.size =MemListi.size - size; MemListi+1.info =f; MemListi.size=size; MemL=u ; Display(); /*/*函數(shù)名:del()/*功能:釋放一塊內(nèi)存/*void del()-*/*/*/*/(int i,numbe
7、r; char temp10; printf(Please Inupt the NUMER you want to stop:);gets(temp); number=atoi(temp); if(MemL = u) ( MemL = f; if( MemListnumber+1.info = f) ( MemListnumber.size += MemListnumber+1.size; for(i=number+1;iMEMSIZE-1 & MemL!=e; i+) MemListi=MemListi+1; if(
8、MemL = f) ( MemListnumber-1.size += MemListnumber.size; for(i=number;iMEMSIZE-1 & MemL!=e; i+) MemListi=MemListi+1; else ( printf(This Number is NOT exist or is NOT used!n); getch(); Display(); /*/ TOC o 1-5 h z /*函數(shù)名:Display()*/*功能:顯示內(nèi)存狀態(tài)*/*/void Display() ( int i,used=0; c
9、lrscr(); printf(nn);printf(%5s%15s%15s%15sn,Number,Start,Size,Info); printf(n);for(i=0;iMEMSIZE & MemL != e;i+) ( if(MemL = u) used += MemListi.size;printf(%5d%15d%15d%15sn,i,MemListi.start,MemListi.size,MemL = u?USED:FREE);printf(n);printf(TotalSize:%-10dUsed:%-10dFree:%-
10、10dn,MEMSIZE,used,MEMSIZE-used);printf(nnPress Any Key to Return.n); getch(); TOC o 1-5 h z /*/*函數(shù)名:Main()*/*功能:主函數(shù)*/*/main()(char ch;InitAll();while(1)(clrscr();printf(Memory Managern);printf(=n) ;printf(1. Getlock use the FIRSTFIT method n);printf(2.Geblock usethe BESTFITmethod n);printf(3.Free a block n);printf(4.Display Meminfomationn);pr
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(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ì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 物業(yè)租賃管理合同協(xié)議
- 房屋轉(zhuǎn)讓協(xié)議合同書
- 安置房買賣協(xié)議合同
- 小學(xué)六英語試卷答案
- 賣魚銷售合同范本
- 個(gè)人一周工作計(jì)劃
- 冷凍品供貨合同范本
- 三年級(jí)下冊(cè)音樂教案
- 醫(yī)院規(guī)培合同范本
- 加油站清洗工程合同范本
- 2025包頭青山賓館有限公司面向社會(huì)公開招聘18人筆試參考題庫附帶答案詳解
- 課件-DeepSeek從入門到精通
- 2025至2030年中國毛絨卡通玩具數(shù)據(jù)監(jiān)測研究報(bào)告
- 2025年度智能充電樁場地租賃合同范本3篇
- 2024年蕪湖職業(yè)技術(shù)學(xué)院高職單招語文歷年參考題庫含答案解析
- 17J008擋土墻(重力式、衡重式、懸臂式)圖示圖集
- 北師大版三年級(jí)下冊(cè)數(shù)學(xué)口算題練習(xí)1000道帶答案
- 技術(shù)推廣服務(wù)合同模板五篇
- 《智能制造技術(shù)基礎(chǔ)》課件-第3章 智能制造加工技術(shù)
- 心電監(jiān)護(hù)儀的操作及注意事項(xiàng) 課件
- GB/T 718-2024鑄造用生鐵
評(píng)論
0/150
提交評(píng)論