操作系统动态内存分配_第1页
操作系统动态内存分配_第2页
操作系统动态内存分配_第3页
操作系统动态内存分配_第4页
操作系统动态内存分配_第5页
已阅读5页,还剩2页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、package com.gaojingdian.arithmetic;import java.io.ioexception;import java.util.arraylist;import java.util.linkedlist;import java.util.list;import com.gaojingdian.dataframe.pcb;import com.gaojingdian.dataframe.subarea;import com.gaojingdian.mainmemorysubarea.mainmemorysubarea;import com.gaojingdian.m

2、ainmemorysubarea.revokememory;/* * 最佳适应算法 * */public class bestfit extends fcfsprivate list readylist=new arraylist(); /就绪队列private list allocationlist=new linkedlist();/已分分配分区队列private static mainmemorysubarea mms=null;private pcb lastpcb=null;private subarea revokesubarea=null;/当前要释放的分区private lis

3、t emptysubarea=null;/空闲队列private list list=null;/中间容器staticmms=new mainmemorysubarea();/用fcfs调度算法从后备队列中往内存中调入满足条件的作业,并用最佳适应算法为作业分配内存空间private void enterreadylist() throws ioexceptionmms.initfreelist();if(emptysubarea=null)emptysubarea=mms.getsubarealist();for(int i=0;ilist.size();i+)int j=0;j=this.g

4、etindex(list.get(i);if(j!=-1)readylist.add(list.get(i);if(emptysubarea.get(j).getsize()-list.get(i).getprocesssize()=subarea.unalteredsize)subarea rsb=new subarea();rsb.setsize(emptysubarea.get(j).getsize();rsb.setbeginaddress(emptysubarea.get(j).getbeginaddress();rsb.setpcbid(list.get(i).getid();al

5、locationlist.add(rsb);emptysubarea.remove(emptysubarea.get(j);elsesubarea sa=emptysubarea.get(j);subarea rsb=new subarea();rsb.setsize(list.get(i).getprocesssize();rsb.setbeginaddress(sa.getbeginaddress();rsb.setpcbid(list.get(i).getid();allocationlist.add(rsb);sa.setbeginaddress(sa.getbeginaddress(

6、)+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);/执行进程,并回收内存空间public void bestfit() throws ioexceptionpcb pcb=null;int temp=10000;int index=0;while(true)list=super.selectprocess(readylist, lastpcb);this.

7、enterreadylist();temp=10000;if(readylist.size()!=0)if(this.getcount()!=readylist.size()for(int i=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=r

8、eadylist.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,revokesu

9、barea);elsebreak;/判断就绪队列中还有没有为被执行的进程private int getcount()int count=0;for(int i=0;ireadylist.size();i+)if(readylist.get(i).getlogo()=1)count+;return count;/返回空闲分区中大小最合适的分区的下标private int getindex(pcb pcb)int temp=10000;int index=-1;for(int i=0;iemptysubarea.size();i+)if(pcb.getprocesssize()=emptysuba

10、rea.get(i).getsize()&(emptysubarea.get(i).getsize()-pcb.getprocesssize()temp)temp=emptysubarea.get(i).getsize()-pcb.getprocesssize();index=i;return index;public list getallocationlist() return allocationlist;public void setallocationlist(list allocationlist) this.allocationlist = allocationlist;publ

11、ic list getemptysubarea() return emptysubarea;public void setemptysubarea(list emptysubarea) this.emptysubarea = emptysubarea;public list getreadylist() return readylist;public void setreadylist(list readylist) this.readylist = readylist;package com.gaojingdian.arithmetic;import java.io.ioexception;

12、import java.util.arraylist;import java.util.linkedlist;import java.util.list;import com.gaojingdian.dataframe.pcb;import com.gaojingdian.dataframe.subarea;import com.gaojingdian.mainmemorysubarea.mainmemorysubarea;import com.gaojingdian.mainmemorysubarea.revokememory;import com.gaojingdian.test.test

13、;import com.gaojingdian.worklist.worklists;/* * 首次适应算法 * author gaojingdian * */public class firstfit extends fcfsprivate list readylist=new arraylist(); /就绪队列private list allocationlist=new linkedlist();/已分分配分区队列private static mainmemorysubarea mms=null;private pcb lastpcb=null;private subarea revo

14、kesubarea=null;/当前要释放的分区private list emptysubarea=null;/空闲队列private list list=null;/中间容器staticmms=new mainmemorysubarea();/用fcfs调度算法从后备队列中往内存中调入满足条件的作业,并用首次适应算法为作业分配内存空间private void enterreadylist() throws ioexceptionmms.initfreelist();if(emptysubarea=null)emptysubarea=mms.getsubarealist();for(int i

15、=0;ilist.size();i+)int j=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)subarea rsb=new subarea();rsb.setsize(emptysubarea.get(j).getsize();rsb.s

16、etbeginaddress(emptysubarea.get(j).getbeginaddress();rsb.setpcbid(list.get(i).getid();allocationlist.add(rsb);emptysubarea.remove(emptysubarea.get(j);elsesubarea sa=emptysubarea.get(j);subarea rsb=new subarea();rsb.setsize(list.get(i).getprocesssize();rsb.setbeginaddress(sa.getbeginaddress();rsb.set

17、pcbid(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);/执行进程,并回收内存空间public void firstfit() throws ioexcep

18、tionpcb pcb=null;int temp=10000;int index=0;while(true)list=super.selectprocess(readylist, lastpcb);this.enterreadylist();temp=10000;if(readylist.size()!=0)if(this.getcount()!=readylist.size()for(int i=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

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论