C++模擬操作系統(tǒng)實(shí)驗(yàn)內(nèi)存管理_第1頁(yè)
C++模擬操作系統(tǒng)實(shí)驗(yàn)內(nèi)存管理_第2頁(yè)
C++模擬操作系統(tǒng)實(shí)驗(yàn)內(nèi)存管理_第3頁(yè)
已閱讀5頁(yè),還剩5頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

模擬操作系統(tǒng)內(nèi)存管理實(shí)驗(yàn)實(shí)驗(yàn)名稱:模擬操作系統(tǒng)內(nèi)存管理。班級(jí):軟件1101班姓名:譚小兵通過(guò)實(shí)驗(yàn)了解操作系統(tǒng)內(nèi)存管理最先適應(yīng)法的主要技術(shù),幫助了解在不同的存儲(chǔ)管理方式下,應(yīng)怎樣實(shí)現(xiàn)主存空間的分配和回收。二、實(shí)驗(yàn)內(nèi)容:設(shè)計(jì)一個(gè)按照最先適應(yīng)法實(shí)現(xiàn)操作系統(tǒng)內(nèi)存管理的程序收。三、基本設(shè)計(jì):采用最先適應(yīng)法模擬主存中內(nèi)存的分配和回收。除相應(yīng)節(jié)點(diǎn)即可。由此便完成了整個(gè)模擬內(nèi)存管理?;玖鞒蹋涸创a:#include<iostream>#include<string>#include<process.h>usingnamespacestd;#defineMAX1048576//定義數(shù)據(jù)結(jié)構(gòu)//進(jìn)程所占內(nèi)存classprocess{public:stringname;longintsize;longintstart;longintend;//boolstate;process*next;process*befor;};//鏈表表頭,存儲(chǔ)進(jìn)程數(shù)classHead{public:longintcount;process*next;};//定義掛起隊(duì)列classOut{public:longintcount;process*next;};//從內(nèi)存空間由上往下搜索合適的空間并裝入內(nèi)存longintadd_pro(Head*head,process*p)//返回1,表示插入成功;返回0表示插入失敗{process*p1=head->next;//搜索插入位置if(0==p1)//內(nèi)存為空{(diào)head->next=p;p->start=10*1024;p->end=p->size+p->befor=0;p->next=0;return1;}else//如果內(nèi)存中有進(jìn)程{longinttemp=p1->start-10240;if(p->size<=temp)//如果第一個(gè)進(jìn)程前面有足夠空間,cutinbeforep1{p->next=head->next;head->next->befor=p;p->befor=0;head->next=p;p->start=10240;p->end=p->size+10240;return1;}else//在兩個(gè)進(jìn)程間尋找合適位置while(p1->next!=0)//當(dāng)p1不是指向最后一個(gè)進(jìn)程{tempp1->next->startp1->end;//if(p->sizetemp)//搜索到了合適位置,cutinafterp1{p->next=p1->next;p1->next->befor=p;p1->next=p;p->befor=p1;p->start=p1->end;p->end=p->start+return1;}p1=p1->next;}//都沒(méi)找到可插入的位置if((p1->end+p->size)<=MAX)//內(nèi)存足夠大,允許進(jìn)程插入到內(nèi)存末尾,此時(shí)p1指向最后一個(gè)節(jié)點(diǎn)

{}else

p->next=0;p->befor=p1;p1->next=p;p->start=p1->end;p->end=p->start+p->size;return1;return0;//返回0,表示插入失敗}}//add進(jìn)程voidin_pro(Head*head){process*pnewprocess;//cout<<"請(qǐng)輸入進(jìn)程名:";cin>>p->name;cout<<"longintkb,bb;cout<<"多少cin>>kb;cout<<"多少cin>>bb;p->size=1024*kbp->next=0;p->befor=0;kb=add_pro(head,p);if(kb==0)cout<<"進(jìn)程添加失敗!\n";elsecout<<"進(jìn)程添加成功!\n";system("pause");system("cls");return;}//kill進(jìn)程voidkill(Head*head){cout<<"請(qǐng)輸入要kill的進(jìn)程名:";stringnam;cin>>nam;process*p=head->next;while(p){if(p->name==break;p=p->next;}if(0==p){cout<<"未找到進(jìn)程:"<<nam<<"!"<<endl;system("pause");system("cls");return;}//刪除就緒隊(duì)列中p節(jié)點(diǎn)if(head->next==p)//p是第一個(gè)節(jié)點(diǎn){head->next=p->next;if(0!=p->next)p->next->befor=0;}elseif(p->next==0)//p是最后一個(gè)節(jié)點(diǎn){p->befor->next=0;p->befor=0;}else//中間節(jié)點(diǎn){p->next->befor=p->befor;p->befor->next=p->next;}deletep;cout<<"成功刪除進(jìn)程:"<<nam<<'!'<<endl;system("pause");system("cls");}//掛起進(jìn)程voidout_pro(Head*head,Out*out){cout<<"請(qǐng)輸入要掛起的進(jìn)程名:";stringnam;cin>>nam;process*phead->next;;//head鏈表process*p1out->next;;//outwhile(p0)//搜索要掛起的進(jìn)程{if(p->name==break;p=p->next;}if(0==p)//無(wú)相關(guān)進(jìn)程{cout<<"找不到進(jìn)程:"<<nam<<"!"<<endl;system("pause");system("cls");return;}//處理就緒隊(duì)列,p指向要解掛節(jié)點(diǎn)if(head->next==p)//要掛起的進(jìn)程在第一個(gè){head->next=p->next;if(0p->next)//p->next->befor0;}elseif(p->next==0)//要掛起的進(jìn)程在最后一個(gè){p->befor->next=0;p->befor=0;}else//要掛起的進(jìn)程在中間{}//done

p->befor->next=p->next;p->next->befor=p->befor;//處理掛起序列,p指向要插入掛起隊(duì)列的節(jié)點(diǎn),p1指向掛起隊(duì)列第一個(gè)節(jié)點(diǎn)if(0==p1)//掛起鏈表為空{(diào)}else{}

out->next=p;p->befor=0;while(0!=p1->next)//p1指向掛起進(jìn)程鏈表的末尾p1=p1->next;p1->next=p;p->befor=p1;p->next=0;//donesystem("cls");}//解掛進(jìn)程voidrein_pro(Head*head,Out*out){cout<<"請(qǐng)輸入要解掛的進(jìn)程名:";stringnam;cin>>nam;//process*p1head->next;;//指向移動(dòng)源鏈表process*pout->next;;//outwhile(0p){if(p->name==break;p=p->next;}if(0==p)//無(wú)相關(guān)進(jìn)程{cout<<"找不到進(jìn)程:"<<nam<<"!"<<endl;system("pause");system("cls");return;}//刪除掛起隊(duì)列中的pif(out->next==p)//要?jiǎng)h除的進(jìn)程在第一個(gè){out->next=p->next;if(0p->next)//pp->next->befor0;}elseif(p->next==0)//要?jiǎng)h除的進(jìn)程在最后一個(gè){p->befor->next=0;}else//要掛起的進(jìn)程在中間{p->befor->next=p->next;p->next->befor=p->befor;}//doneadd_pro(head,p);cout<<"成功解掛進(jìn)程:"<<nam<<endl;system("pause");system("cls");return;}intmain(){Head*headnewHead;//head->next0;head->count=0;Out*outnewOut;//out->next0;longinttemp=0;process*p=head->next;process*p1=out->next;while(1){cout<<"操作系統(tǒng)內(nèi)存管理模擬實(shí)驗(yàn)!內(nèi)存大小1M\n"<<endl;cout<<"內(nèi)存進(jìn)程存儲(chǔ)狀態(tài):"<<endl;cout<<"\t操作系統(tǒng)占用:10KB"<<endl;p=head->next;while(0!=p){cout<<"\t 進(jìn) 程 名 :"<<p->name<<"\t 大小:"<<(p->size)/1024<<"K"<<(p->size)%1024<<"B\t址:"<<p->end<<endl;p=p->next;

起始地址:"<<p->start<<"結(jié)束地}p=head->next;cout<<"內(nèi)存剩余空間段:\n";if(0==p)//無(wú)進(jìn)程cout<<'\t'<<MAX;else//有進(jìn)程{if((p->start-10240)!=0)cout<<'\t'<<(p->start-10240)<<endl;if(0==p->next)//僅有一個(gè)進(jìn)程時(shí)cout<<'\t'<<MAX-(p->end)<<endl;elsewhile(1)//至少有兩個(gè)進(jìn)程,p->next!=0{temp=p->next->start-if(temp)cout<<'\t'<<temp<<endl;p=p->next;if(0==p->next)//p指向最后一個(gè)節(jié)點(diǎn)時(shí){cout<<'\t'<<MAX-(p->end)<<endl;break;}}}cout<<"\n掛起隊(duì)列:"<<endl;p1=out->next;while(p1){cout<<"\t 進(jìn) 程 名 :"<<p1->name<<"\t 小:"<<(p1->size)/1024<<"K"<<(p1->size)%1024<<'B'<<endl;p1=p1->next;}cout<<"\n1、加入進(jìn)程\n

溫馨提示

  • 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ì)自己和他人造成任何形式的傷害或損失。

最新文檔