已阅读5页,还剩2页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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();/已分分配分区队列privatestaticMainMemorySubareamms=null;privatePCBlastPCB=null;privateSubarearevokeSubarea=null;/当前要释放的分区privateListemptySubarea=null;/空闲队列privateListlist=null;/中间容器staticmms=newMainMemorySubarea();/用FCFS调度算法从后备队列中往内存中调入满足条件的作业,并用最佳适应算法为作业分配内存空间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);/执行进程,并回收内存空间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;/判断就绪队列中还有没有为被执行的进程privateintgetCount()intcount=0;for(inti=0;ireadyList.size();i+)if(readyList.get(i).getLogo()=1)count+;returncount;/返回空闲分区中大小最合适的分区的下标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();/已分分配分区队列privatestaticMainMemorySubareamms=null;privatePCBlastPCB=null;privateSubarearevokeSubarea=null;/当前要释放的分区privateListemptySubarea=null;/空闲队列privateListlist=null;/中间容器staticmms=newMainMemorySubarea();/用FCFS调度算法从后备队列中往内存中调入满足条件的作业,并用首次适应算法为作业分配内存空间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);/执行进程,并回收内存空间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. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年河南省地质局所属事业单位招才引智高层次人才40人考试笔试参考题库附答案解析
- 2026中国储备粮管理集团有限公司黑龙江分公司省内粮食行业产教融合共同体院校招聘40人笔试考试备考题库及答案解析
- 2025弋阳县总医院人民医院院区招聘8名临床医师笔试考试备考试题及答案解析
- 2025河南师范大学2025年招聘员额制工作人员(硕士)4人考试笔试模拟试题及答案解析
- 2025上海静安区区管企业招聘中层管理人员17人笔试考试参考试题及答案解析
- 2025南昌县人民医院招聘1名超声医学科医生考试笔试参考题库附答案解析
- 南充市房地产管理局2025年公开遴选参照管理人员(2人)考试笔试备考题库及答案解析
- 2025年江西省赣湘发展投资集团有限公司招聘合同制工作人员3人笔试考试备考试题及答案解析
- 2026天津市卫生健康委员会所属天津市第三中心医院招聘60人笔试考试备考试题及答案解析
- 2025广东韶关乐昌市市场监督管理局编外人员招聘2人考试笔试参考题库附答案解析
- 2025云南交投集团公路建设有限公司生产人员招聘8人笔试历年参考题库附带答案详解
- 乡村垃圾模拟政协提案模板
- 2025昆明市消防救援支队政府专职消防员招聘(188人)笔试考试参考试题及答案解析
- 2025广东东莞市樟木头镇招聘编外聘用人员14人笔试考试参考试题及答案解析
- 2025年大学《艺术鉴赏》各章节测试题与答案
- 2025至2030中国合成纤维行业项目调研及市场前景预测评估报告
- IMPA船舶物料指南(电子版)
- 【MOOC】以案说法-中南财经政法大学 中国大学慕课MOOC答案
- GA 1026-2012机动车驾驶人考试内容和方法
- MBA市场营销课程考试范围(32题及答案)
- 宝钢作业长制详解课件
评论
0/150
提交评论