操作系统动态内存分配.doc操作系统动态内存分配.doc

收藏 分享

资源预览需要最新版本的Flash Player支持。
您尚未安装或版本过低,建议您

PACKAGECOMGAOJINGDIANARITHMETIC;IMPORTJAVAIOIOEXCEPTION;IMPORTJAVAUTILARRAYLIST;IMPORTJAVAUTILLINKEDLIST;IMPORTJAVAUTILLIST;IMPORTCOMGAOJINGDIANDATAFRAMEPCB;IMPORTCOMGAOJINGDIANDATAFRAMESUBAREA;IMPORTCOMGAOJINGDIANMAINMEMORYSUBAREAMAINMEMORYSUBAREA;IMPORTCOMGAOJINGDIANMAINMEMORYSUBAREAREVOKEMEMORY;/最佳适应算法/PUBLICCLASSBESTFITEXTENDSFCFS{PRIVATELISTPCBREADYLISTNEWARRAYLISTPCB;//就绪队列PRIVATELISTSUBAREAALLOCATIONLISTNEWLINKEDLISTSUBAREA;//已分分配分区队列PRIVATESTATICMAINMEMORYSUBAREAMMSNULL;PRIVATEPCBLASTPCBNULL;PRIVATESUBAREAREVOKESUBAREANULL;//当前要释放的分区PRIVATELISTSUBAREAEMPTYSUBAREANULL;//空闲队列PRIVATELISTPCBLISTNULL;//中间容器STATIC{MMSNEWMAINMEMORYSUBAREA;}//用FCFS调度算法从后备队列中往内存中调入满足条件的作业,并用最佳适应算法为作业分配内存空间PRIVATEVOIDENTERREADYLISTTHROWSIOEXCEPTION{MMSINITFREELIST;IFEMPTYSUBAREANULLEMPTYSUBAREAMMSGETSUBAREALIST;FORINTI0;ILISTSIZE;I{INTJ0;JTHISGETINDEXLISTGETI;IFJ1{READYLISTADDLISTGETI;IFEMPTYSUBAREAGETJGETSIZELISTGETIGETPROCESSSIZESUBAREAUNALTEREDSIZE{SUBAREARSBNEWSUBAREA;RSBSETSIZEEMPTYSUBAREAGETJGETSIZE;RSBSETBEGINADDRESSEMPTYSUBAREAGETJGETBEGINADDRESS;RSBSETPCBIDLISTGETIGETID;ALLOCATIONLISTADDRSB;EMPTYSUBAREAREMOVEEMPTYSUBAREAGETJ;}ELSE{SUBAREASAEMPTYSUBAREAGETJ;SUBAREARSBNEWSUBAREA;RSBSETSIZELISTGETIGETPROCESSSIZE;RSBSETBEGINADDRESSSAGETBEGINADDRESS;RSBSETPCBIDLISTGETIGETID;ALLOCATIONLISTADDRSB;SASETBEGINADDRESSSAGETBEGINADDRESSLISTGETIGETPROCESSSIZE;SASETSIZESAGETSIZELISTGETIGETPROCESSSIZE;}LISTGETISETLOGO21;BREAK;}IFJ1LISTGETISETLOGO11;}}//执行进程,并回收内存空间PUBLICVOIDBESTFITTHROWSIOEXCEPTION{PCBPCBNULL;INTTEMP10000;INTINDEX0;WHILETRUE{LISTSUPERSELECTPROCESSREADYLIST,LASTPCB;THISENTERREADYLIST;TEMP10000;IFREADYLISTSIZE0{IFTHISGETCOUNTREADYLISTSIZE{FORINTI0;IREADYLISTSIZE;I{IFREADYLISTGETIGETARRIVETIMETEMPREADYLISTGETIGETLOGO0READYLISTGETIGETLOGO21READYLISTGETIGETLOGO10{TEMPREADYLISTGETIGETARRIVETIME;INDEXI;}}PCBREADYLISTGETINDEX;IFLASTPCBNULLPCBSETBEGINTIMEPCBGETARRIVETIME;ELSEPCBSETBEGINTIMELASTPCBGETENDTIME;PCBSETENDTIMEPCBGETBEGINTIMEPCBGETRUNTIME;PCBSETLOGO1;LASTPCBPCB;REVOKESUBAREAREVOKEMEMORYSELECTREVOKEALLOCATIONLIST,PCB;REVOKEMEMORYREVOKEMEMORYEMPTYSUBAREA,REVOKESUBAREA;}ELSE{BREAK;}}}}//判断就绪队列中还有没有为被执行的进程PRIVATEINTGETCOUNT{INTCOUNT0;FORINTI0;IREADYLISTSIZE;IIFREADYLISTGETIGETLOGO1COUNT;RETURNCOUNT;}//返回空闲分区中大小最合适的分区的下标PRIVATEINTGETINDEXPCBPCB{INTTEMP10000;INTINDEX1;FORINTI0;IEMPTYSUBAREASIZE;IIFPCBGETPROCESSSIZEEMPTYSUBAREAGETIGETSIZEEMPTYSUBAREAGETIGETSIZEPCBGETPROCESSSIZETEMP{TEMPEMPTYSUBAREAGETIGETSIZEPCBGETPROCESSSIZE;INDEXI;}RETURNINDEX;}PUBLICLISTSUBAREAGETALLOCATIONLIST{RETURNALLOCATIONLIST;}PUBLICVOIDSETALLOCATIONLISTLISTSUBAREAALLOCATIONLIST{THISALLOCATIONLISTALLOCATIONLIST;}PUBLICLISTSUBAREAGETEMPTYSUBAREA{RETURNEMPTYSUBAREA;}PUBLICVOIDSETEMPTYSUBAREALISTSUBAREAEMPTYSUBAREA{THISEMPTYSUBAREAEMPTYSUBAREA;}PUBLICLISTPCBGETREADYLIST{RETURNREADYLIST;}PUBLICVOIDSETREADYLISTLISTPCBREADYLIST{THISREADYLISTREADYLIST;}}PACKAGECOMGAOJINGDIANARITHMETIC;IMPORTJAVAIOIOEXCEPTION;IMPORTJAVAUTILARRAYLIST;IMPORTJAVAUTILLINKEDLIST;IMPORTJAVAUTILLIST;IMPORTCOMGAOJINGDIANDATAFRAMEPCB;IMPORTCOMGAOJINGDIANDATAFRAMESUBAREA;IMPORTCOMGAOJINGDIANMAINMEMORYSUBAREAMAINMEMORYSUBAREA;IMPORTCOMGAOJINGDIANMAINMEMORYSUBAREAREVOKEMEMORY;IMPORTCOMGAOJINGDIANTESTTEST;IMPORTCOMGAOJINGDIANWORKLISTWORKLISTS;/首次适应算法AUTHORGAOJINGDIAN/PUBLICCLASSFIRSTFITEXTENDSFCFS{PRIVATELISTPCBREADYLISTNEWARRAYLISTPCB;//就绪队列PRIVATELISTSUBAREAALLOCATIONLISTNEWLINKEDLISTSUBAREA;//已分分配分区队列PRIVATESTATICMAINMEMORYSUBAREAMMSNULL;PRIVATEPCBLASTPCBNULL;PRIVATESUBAREAREVOKESUBAREANULL;//当前要释放的分区PRIVATELISTSUBAREAEMPTYSUBAREANULL;//空闲队列PRIVATELISTPCBLISTNULL;//中间容器STATIC{MMSNEWMAINMEMORYSUBAREA;}//用FCFS调度算法从后备队列中往内存中调入满足条件的作业,并用首次适应算法为作业分配内存空间PRIVATEVOIDENTERREADYLISTTHROWSIOEXCEPTION{MMSINITFREELIST;IFEMPTYSUBAREANULLEMPTYSUBAREAMMSGETSUBAREALIST;FORINTI0;ILISTSIZE;I{INTJ0;FOR;JEMPTYSUBAREASIZE;J{IFLISTGETIGETPROCESSSIZEEMPTYSUBAREAGETJGETSIZE{READYLISTADDLISTGETI;IFEMPTYSUBAREAGETJGETSIZELISTGETIGETPROCESSSIZESUBAREAUNALTEREDSIZE{SUBAREARSBNEWSUBAREA;RSBSETSIZEEMPTYSUBAREAGETJGETSIZE;RSBSETBEGINADDRESSEMPTYSUBAREAGETJGETBEGINADDRESS;RSBSETPCBIDLISTGETIGETID;ALLOCATIONLISTADDRSB;EMPTYSUBAREAREMOVEEMPTYSUBAREAGETJ;}ELSE{SUBAREASAEMPTYSUBAREAGETJ;SUBAREARSBNEWSUBAREA;RSBSETSIZELISTGETIGETPROCESSSIZE;RSBSETBEGINADDRESSSAGETBEGINADDRESS;RSBSETPCBIDLISTGETIGETID;ALLOCATIONLISTADDRSB;SASETBEGINADDRESSSAGETBEGINADDRESSLISTGETIGETPROCESSSIZE;SASETSIZESAGETSIZELISTGETIGETPROCESSSIZE;}LISTGETISETLOGO21;BREAK;}}IFJEMPTYSUBAREASIZELISTGETISETLOGO11;}}//执行进程,并回收内存空间PUBLICVOIDFIRSTFITTHROWSIOEXCEPTION{PCBPCBNULL;INTTEMP10000;INTINDEX0;WHILETRUE{LISTSUPERSELECTPROCESSREADYLIST,LASTPCB;THISENTERREADYLIST;TEMP10000;IFREADYLISTSIZE0{IFTHISGETCOUNTREADYLISTSIZE{FORINTI0;IREADYLISTSIZE;I{IFREADYLISTGETIGETARRIVETIMETEMPREADYLISTGETIGETLOGO0READYLISTGETIGETLOGO21READYLISTGETIGETLOGO10{TEMPREADYLISTGETIGETARRIVETIME;INDEXI;}}PCBREADYLISTGETINDEX;IFLASTPCBNULLPCBSETBEGINTIMEPCBGETARRIVETIME;ELSEPCBSETBEGINTIMELASTPCBGETENDTIME;PCBSETENDTIMEPCBGETBEGINTIMEPCBGETRUNTIME;PCBSETLOGO1;LASTPCBPCB;REVOKESUBAREAREVOKEMEMORYSELECTREVOKEALLOCATIONLIST,PCB;REVOKEMEMORYREVOKEMEMORYEMPTYSUBAREA,REVOKESUBAREA;}ELSE{BREAK;}}}}PRIVATEINTGETCOUNT{INTCOUNT0;FORINTI0;IREADYLISTSIZE;IIFREADYLISTGETIGETLOGO1COUNT;RETURNCOUNT;}PUBLICLISTSUBAREAGETALLOCATIONLIST{RETURNALLOCATIONLIST;}PUBLICVOIDSETALLOCATIONLISTLISTSUBAREAALLOCATIONLIST{THISALLOCATIONLISTALLOCATIONLIST;}PUBLICLISTSUBAREAGETEMPTYSUBAREA{RETURNEMPTYSUBAREA;}PUBLICVOIDSETEMPTYSUBAREALISTSUBAREAEMPTYSUBAREA{THISEMPTYSUBAREAEMPTYSUBAREA;}PUBLICLISTPCBGETREADYLIST{RETURNREADYLIST;}PUBLICVOIDSETREADYLISTLISTPCBREADYLIST{THISREADYLISTREADYLIST;}}
编号:201311211211119135    类型:共享资源    大小:38.00KB    格式:DOC    上传时间:2013-11-21
  
6
关 键 词:
专业文献 学术论文 精品文档 操作系统
  人人文库网所有资源均是用户自行上传分享,仅供网友学习交流,未经上传用户书面授权,请勿作他用。
关于本文
本文标题:操作系统动态内存分配.doc
链接地址:http://www.renrendoc.com/p-109135.html

当前资源信息

4.0
 
(2人评价)
浏览:9次
liyun上传于2013-11-21

官方联系方式

客服手机:17625900360   
2:不支持迅雷下载,请使用浏览器下载   
3:不支持QQ浏览器下载,请用其他浏览器   
4:下载后的文档和图纸-无水印   
5:文档经过压缩,下载后原文更清晰   

精品推荐

相关阅读

人人文库
关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服客服 - 联系我们

网站客服QQ:2846424093    人人文库上传用户QQ群:460291265   

[email protected] 2016-2018  renrendoc.com 网站版权所有   南天在线技术支持

经营许可证编号:苏ICP备12009002号-5