欢迎来到天天文库
浏览记录
ID:55295813
大小:32.00 KB
页数:10页
时间:2020-05-09
《计算机操作系统 内存动态分配和回收模拟实现.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、//COPYRIGHT2010tragedyringfinger.ALLRIGHTSRESERVED.#include#includeusingnamespacestd;//¿ÕÏзÖÇø20¸ö£¬ÒÑ·ÖÅä·ÖÇø20¸östructempty//¿ÕÏзÖÇø±í{intaddress_of_start;//ÆðʼµØÖ·intsize_of_empty;//¿ÕÏдóСintnext;intyesorno;//ÊÇ·ñ¿ÕÏÐ,1¿ÕÏУ¬ÓÐЧ}Empty[20];struc
2、tnot_empty//ÒÑ·ÖÅä·ÖÇø±í{intpid;intaddress_of_start;intsize_of_notempty;intnext;intyesorno;//ÊÇ·ñ·ÖÅ䣬1·ÖÅäÓÐЧ}Not_Empty[20];intCountOfEmpty=1,CountOfNotEmpty=0;//´Ó0¿ªÊ¼¼ÆÊýintMin_Size=2;//²»¿É·Ö¸îµÄ×îС·ÖÇøintMax_Size=300;//×î´ó¿Õ¼ä300X300=90000intNum_Of_Row=30;//ÏÔʾ
3、ʱ£¬ºáÅŸöÊýintNum_Of_Area=20;//¿ÕÏзÖÇøºÍ·ÖÅä·ÖÇøµÄ×î´ó·ÖÇøÊýintenough(intSize_Of_NotEmpty)//ÊÇ·ñÓÐ×ã¹»µÄ¿ÕÏпռä{inti;for(i=0;i=Size_Of_NotEmpty+Min_Size)returni;}return-1;}intwhere(intnum,inta[])//ÕÒµ½ÆðʼµØַΪnum
4、µÄÇøÓòµÄϱ꣬a0=-1£¬ÔòÔÚNot_EmptyÖУ¬Ï±êΪa1£»a1=-1ÔÚEmptyÖУ¬Ï±êΪa0{inti=0;while(i5、1;}return-1;}intfenpei(){inttemp,i;CountOfNotEmpty+=1;Not_Empty[CountOfNotEmpty].yesorno=0;for(i=0;i>Not_Empty[i].pid>>Not_Empty[i].size_of_notempty;if(Not_Empty6、[i].pid<07、8、Not_Empty[i].pid>99){CountOfNotEmpty-=1;cout<<"½ø³ÌºÅ0~99";return-1;}for(intii=0;ii9、=0)//ÕÒµ½ÄÜÂú×ãÇëÇóµÄ¿ÕÏзÖÇø{Not_Empty[i].address_of_start=Empty[temp].address_of_start;Not_Empty[i].yesorno=1;Empty[temp].address_of_start+=Not_Empty[i].size_of_notempty;Empty[temp].size_of_empty-=Not_Empty[i].size_of_notempty;}else{CountOfNotEmpty-=1;cout<<"δÕÒµ½×ã¹»´10、óµÄ¿ÕÏзÖÇø";return-1;}}return0;}intfront(inti,int&a)//iΪ´ý»ØÊÕÇøÔÚNot_EmptyÖеÄϱꡣa´æ¶ÔÓ¦
5、1;}return-1;}intfenpei(){inttemp,i;CountOfNotEmpty+=1;Not_Empty[CountOfNotEmpty].yesorno=0;for(i=0;i>Not_Empty[i].pid>>Not_Empty[i].size_of_notempty;if(Not_Empty
6、[i].pid<0
7、
8、Not_Empty[i].pid>99){CountOfNotEmpty-=1;cout<<"½ø³ÌºÅ0~99";return-1;}for(intii=0;ii
9、=0)//ÕÒµ½ÄÜÂú×ãÇëÇóµÄ¿ÕÏзÖÇø{Not_Empty[i].address_of_start=Empty[temp].address_of_start;Not_Empty[i].yesorno=1;Empty[temp].address_of_start+=Not_Empty[i].size_of_notempty;Empty[temp].size_of_empty-=Not_Empty[i].size_of_notempty;}else{CountOfNotEmpty-=1;cout<<"δÕÒµ½×ã¹»´
10、óµÄ¿ÕÏзÖÇø";return-1;}}return0;}intfront(inti,int&a)//iΪ´ý»ØÊÕÇøÔÚNot_EmptyÖеÄϱꡣa´æ¶ÔÓ¦
此文档下载收益归作者所有