可变分区存储管理方式的内存分配和回收

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

free_quantity++; fscanf(文件指针,格式字符串,输入表列);
}
return 1;
}
return 0;
}
void sort()
{
int i,j,p;
for(i=0;i<free_quantity-1;i++){
p=i;
for(j=i+1;j<free_quantity;j++){
if(frees[j].address<frees[p].address){
p=j;
}
}
if(p!=i){
frees[free_quantity]=frees[i];
frees[i]=frees[p];
frees[p]=frees[free_quantity];
}
}
}
void view()
{
int i;
cout<<endl<<"mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm"<< endl;
cout<<"输出空闲区表:\n起始地址分区长度状态\n"<<endl;
for(i=0;i<free_quantity;i++){
(2);
(12);
cout<<frees[i].address;
(10);
cout<<frees[i].length;
(8);
cout<<frees[i].tag<<endl;
}
cout<<endl<<"wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww"< <endl;
cout<<"输出已分分区表:\n起始地址分区长度占用作业名\n"<<endl;
for(i=0;i<occupy_quantity;i++){
(2);
(12);
cout<<occupys[i].address;
(10);
cout<<occupys[i].length;
(8);
cout<<occupys[i].tag<<endl;
}
}
void ear()
{
char job_name[10];
int job_length;
int i,j,flag,t;
cout<<"请输入分配内存的作业名和空间大小:";
cin>>job_name;
cin>>job_length;
flag=0;
for(i=0;i<free_quantity;i++){ ength>=job_length){
flag=1;
}
}
if(flag==0){ ength>=job_length){ddress=frees[i].address; ag,job_name);
occupys[occupy_quantity].length=job_length;
occupy_quantity++;
if(frees[i].length>job_length){
frees[i].address+=job_length;
frees[i].length-=job_length;
}
else{
for(j=i;j<free_quantity-1;j++){
frees[j]=frees[j+1];
}
free_quantity--;
cout<<"内存空间成功:)"<<endl;
}
}
}
void reclaim()ag,job_name)){
flag=i;
address=occupys[i].address;
length=occupys[i].length;
}
}
if(flag==-1){ ddress+frees[i].length)==address){
if(((i+1)<free_quantity)&&(frees[i+1].address==address+length)){
frees[i].length=frees[i].length+frees[i+1].length+length;
for(j=i+1;j<free_quantity;j++){
frees[j]=frees[j+1];
}
free_quantity--;
p=1;
}
else{
frees[i].length+=length;
p=1;
}
}
if(frees[i].address==(address+length)){
frees[i].address=address;
frees[i].length+=length;
p=1;
}
}
if(p==0){
frees[free_quantity].address=address;
frees[free_quantity].length=length;
free_quantity++;
}ddress=-1;ength=0;
strcpy(frees[i].tag,"free");
occupys[i].address=-1;ength=0;
strcpy(occupys[i].tag,"");
}
free_quantity=0;
occupy_quantity=0;
flag=read();
while(flag==1){
sort();
cout<<"选择功能项: (0-退出,1-分配内存,2-回收内存,3-显示内存)\n"<<endl;
cout<<"选择功项(0-3):";
cin>>chioce;
switch(chioce){
case 0:
flag=0;
break;
case 1:
ear();
break;
case 2:
reclaim();
break;
case 3:
view();
break;
default:
cout<<"没有该选项\n"<<endl;
}
}
}。

相关文档
最新文档