欢迎来到天天文库
浏览记录
ID:6699593
大小:30.00 KB
页数:7页
时间:2018-01-22
《操作系统动态内存分配》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、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;import
2、com.gaojingdian.MainMemorySubarea.RevokeMemory;/***最佳适应算法**/publicclassBestFitextendsFCFS{privateListreadyList=newArrayList();//就绪队列privateListallocationList=newLinkedList();//已分分配分区队列privatestaticMainMemorySubareamms=null;privatePCBlastPCB=null;
3、privateSubarearevokeSubarea=null;//当前要释放的分区privateListemptySubarea=null;//空闲队列privateListlist=null;//中间容器static{mms=newMainMemorySubarea();}//用FCFS调度算法从后备队列中往内存中调入满足条件的作业,并用最佳适应算法为作业分配内存空间privatevoidenterReadyList()throwsIOException{mms.initFreeList();if(empty
4、Subarea==null)emptySubarea=mms.getSubareaList();for(inti=0;i5、(emptySubarea.get(j).getSize());rsb.setBeginAddress(emptySubarea.get(j).getBeginAddress());rsb.setPcbId(list.get(i).getId());allocationList.add(rsb);emptySubarea.remove(emptySubarea.get(j));}else{Subareasa=emptySubarea.get(j);Subarearsb=newSubarea();rsb.setSize(list.get(i).6、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;}7、if(j==-1)list.get(i).setLogo1(1);}}//执行进程,并回收内存空间publicvoidbestFit()throwsIOException{PCBpcb=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()){8、for(inti=0;i
5、(emptySubarea.get(j).getSize());rsb.setBeginAddress(emptySubarea.get(j).getBeginAddress());rsb.setPcbId(list.get(i).getId());allocationList.add(rsb);emptySubarea.remove(emptySubarea.get(j));}else{Subareasa=emptySubarea.get(j);Subarearsb=newSubarea();rsb.setSize(list.get(i).
6、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;}
7、if(j==-1)list.get(i).setLogo1(1);}}//执行进程,并回收内存空间publicvoidbestFit()throwsIOException{PCBpcb=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()){
8、for(inti=0;i
此文档下载收益归作者所有