




已阅读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年网络管理能力评估试题及答案
- 医疗健康领域下的幼儿数字化教育资源
- 2025年软考网络管理员考试热点聚焦试题及答案
- 商业物流与数字孪生城市的协同发展
- 护理季度工作总结
- 高考生物一轮复习(全国版) 第8单元 第5课时 体液调节与神经调节的关系
- 一二年级诗词大赛备考试题库500题(供参考)
- 食堂库存物的盘点表
- 单位闲置房屋盘活方案范本
- 美妙的高等数学(上)智慧树知到课后章节答案2023年下江西师范大学
- 新员工入职报到通知书
- 2018年版电工-国家职业技能标准
- 浅谈如何做好财务安全工作
- 电动车分期付款的合同范本
- 高中英语-Live form the Louvre教学设计学情分析教材分析课后反思
- 2023北京高考英语答题卡ok
- 医务科运用PDCA循环提高门诊医生准时出诊率PDCA成果汇报
评论
0/150
提交评论