




已閱讀5頁,還剩2頁未讀, 繼續(xù)免費閱讀
版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
packagecom.gaojingdian.arithmetic;importjava.io.IOException;importjava.util.ArrayList;importjava.util.LinkedList;importjava.util.List;importcom.gaojingdian.DataFrame.PCB;importcom.gaojingdian.DataFrame.Subarea;importcom.gaojingdian.MainMemorySubarea.MainMemorySubarea;importcom.gaojingdian.MainMemorySubarea.RevokeMemory;/*最佳適應算法*/publicclassBestFitextendsFCFSprivateListreadyList=newArrayList();/就緒隊列privateListallocationList=newLinkedList();/已分分配分區(qū)隊列privatestaticMainMemorySubareamms=null;privatePCBlastPCB=null;privateSubarearevokeSubarea=null;/當前要釋放的分區(qū)privateListemptySubarea=null;/空閑隊列privateListlist=null;/中間容器staticmms=newMainMemorySubarea();/用FCFS調度算法從后備隊列中往內存中調入滿足條件的作業(yè),并用最佳適應算法為作業(yè)分配內存空間privatevoidenterReadyList()throwsIOExceptionmms.initFreeList();if(emptySubarea=null)emptySubarea=mms.getSubareaList();for(inti=0;ilist.size();i+)intj=0;j=this.getIndex(list.get(i);if(j!=-1)readyList.add(list.get(i);if(emptySubarea.get(j).getSize()-list.get(i).getProcessSize()=Subarea.unalteredSize)Subarearsb=newSubarea();rsb.setSize(emptySubarea.get(j).getSize();rsb.setBeginAddress(emptySubarea.get(j).getBeginAddress();rsb.setPcbId(list.get(i).getId();allocationList.add(rsb);emptySubarea.remove(emptySubarea.get(j);elseSubareasa=emptySubarea.get(j);Subarearsb=newSubarea();rsb.setSize(list.get(i).getProcessSize();rsb.setBeginAddress(sa.getBeginAddress();rsb.setPcbId(list.get(i).getId();allocationList.add(rsb);sa.setBeginAddress(sa.getBeginAddress()+list.get(i).getProcessSize();sa.setSize(sa.getSize()-list.get(i).getProcessSize();list.get(i).setLogo2(1);break;if(j=-1)list.get(i).setLogo1(1);/執(zhí)行進程,并回收內存空間publicvoidbestFit()throwsIOExceptionPCBpcb=null;inttemp=10000;intindex=0;while(true)list=super.selectProcess(readyList,lastPCB);this.enterReadyList();temp=10000;if(readyList.size()!=0)if(this.getCount()!=readyList.size()for(inti=0;ireadyList.size();i+)if(readyList.get(i).getArriveTime()temp&readyList.get(i).getLogo()=0&readyList.get(i).getLogo2()=1&readyList.get(i).getLogo1()=0)temp=readyList.get(i).getArriveTime();index=i;pcb=readyList.get(index);if(lastPCB=null)pcb.setBeginTime(pcb.getArriveTime();elsepcb.setBeginTime(lastPCB.getEndTime();pcb.setEndTime(pcb.getBeginTime()+pcb.getRunTime();pcb.setLogo(1);lastPCB=pcb;revokeSubarea=RevokeMemory.selectRevoke(allocationList,pcb);RevokeMemory.revokeMemory(emptySubarea,revokeSubarea);elsebreak;/判斷就緒隊列中還有沒有為被執(zhí)行的進程privateintgetCount()intcount=0;for(inti=0;ireadyList.size();i+)if(readyList.get(i).getLogo()=1)count+;returncount;/返回空閑分區(qū)中大小最合適的分區(qū)的下標privateintgetIndex(PCBpcb)inttemp=10000;intindex=-1;for(inti=0;iemptySubarea.size();i+)if(pcb.getProcessSize()=emptySubarea.get(i).getSize()&(emptySubarea.get(i).getSize()-pcb.getProcessSize()temp)temp=emptySubarea.get(i).getSize()-pcb.getProcessSize();index=i;returnindex;publicListgetAllocationList()returnallocationList;publicvoidsetAllocationList(ListallocationList)this.allocationList=allocationList;publicListgetEmptySubarea()returnemptySubarea;publicvoidsetEmptySubarea(ListemptySubarea)this.emptySubarea=emptySubarea;publicListgetReadyList()returnreadyList;publicvoidsetReadyList(ListreadyList)this.readyList=readyList;packagecom.gaojingdian.arithmetic;importjava.io.IOException;importjava.util.ArrayList;importjava.util.LinkedList;importjava.util.List;importcom.gaojingdian.DataFrame.PCB;importcom.gaojingdian.DataFrame.Subarea;importcom.gaojingdian.MainMemorySubarea.MainMemorySubarea;importcom.gaojingdian.MainMemorySubarea.RevokeMemory;importcom.gaojingdian.Test.Test;importcom.gaojingdian.WorkList.WorkLists;/*首次適應算法*authorgaojingdian*/publicclassFirstFitextendsFCFSprivateListreadyList=newArrayList();/就緒隊列privateListallocationList=newLinkedList();/已分分配分區(qū)隊列privatestaticMainMemorySubareamms=null;privatePCBlastPCB=null;privateSubarearevokeSubarea=null;/當前要釋放的分區(qū)privateListemptySubarea=null;/空閑隊列privateListlist=null;/中間容器staticmms=newMainMemorySubarea();/用FCFS調度算法從后備隊列中往內存中調入滿足條件的作業(yè),并用首次適應算法為作業(yè)分配內存空間privatevoidenterReadyList()throwsIOExceptionmms.initFreeList();if(emptySubarea=null)emptySubarea=mms.getSubareaList();for(inti=0;ilist.size();i+)intj=0;for(;jemptySubarea.size();j+)if(list.get(i).getProcessSize()=emptySubarea.get(j).getSize()readyList.add(list.get(i);if(emptySubarea.get(j).getSize()-list.get(i).getProcessSize()=Subarea.unalteredSize)Subarearsb=newSubarea();rsb.setSize(emptySubarea.get(j).getSize();rsb.setBeginAddress(emptySubarea.get(j).getBeginAddress();rsb.setPcbId(list.get(i).getId();allocationList.add(rsb);emptySubarea.remove(emptySubarea.get(j);elseSubareasa=emptySubarea.get(j);Subarearsb=newSubarea();rsb.setSize(list.get(i).getProcessSize();rsb.setBeginAddress(sa.getBeginAddress();rsb.setPcbId(list.get(i).getId();allocationList.add(rsb);sa.setBeginAddress(sa.getBeginAddress()+list.get(i).getProcessSize();sa.setSize(sa.getSize()-list.get(i).getProcessSize();list.get(i).setLogo2(1);break;if(j=emptySubarea.size()list.get(i).setLogo1(1);/執(zhí)行進程,并回收內存空間publicvoidfirstFit()throwsIOExceptionPCBpcb=null;inttemp=10000;intindex=0;while(true)list=super.selectProcess(readyList,lastPCB);this.enterReadyList();temp=10000;if(readyList.size()!=0)if(this.getCount()!=readyList.size()for(inti=0;ireadyList.size();i+)if(readyList.get(i).getArriveTime()temp&readyList.get(i).getLogo()=0&readyList.get(i).getLogo2()=1&readyList.get(i).getLogo1()=0)temp=readyList.get(i).getArriveTime();index=i;pcb=readyList.get(index);if(lastPCB=null)pcb.setBeginTime(pcb.getArriveTime();elsepcb.setBeginTime(lastPCB.getEndTime();pcb.setEndTime(pcb.getBeginTime()+pcb.getRunTime();pcb.set
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 餐飲品牌授權保密條款及競業(yè)禁止協(xié)議
- 企業(yè)財務顧問與財務培訓服務協(xié)議
- 財務人員離職保密協(xié)議及財務軟件使用限制合同
- 債務清償協(xié)議書范本
- 深度參與式股權投資合作協(xié)議范本
- 家庭飲品分包協(xié)議書范本
- 食品安全責任險承保下的采購協(xié)議
- 環(huán)保產(chǎn)業(yè)項目貸款合同范本:綠色金融創(chuàng)新
- 春節(jié)節(jié)后新年復工專題培訓
- 急性腸胃炎的急救護理
- 醫(yī)療廢物交接與記錄的重要性
- 個人極端事件防范應急預案
- (環(huán)境管理)環(huán)境保護與水土保持監(jiān)理實施細則
- 軍事訓練傷的防治
- 國開《化工安全技術》形考任務1-4答案
- 安全生產(chǎn)月“一把手”講安全課件
- 產(chǎn)業(yè)命題賽道命題解決對策參考模板
- 985、211和雙一流大學名單
- 三人合伙經(jīng)營協(xié)議書電子版(2篇)
- 汽車產(chǎn)品認證
- 蛇類解剖生理特征(特種寵物疾病防治)
評論
0/150
提交評論