模拟实现用位示图法管理文件存储空间的分配与回收1(4)

2019-08-31 12:04

}

/************************************** 申请空间操作

***************************************/ work *request(work *w,int WST[256]){

int i,m,n,flag=0;

free_link *p,*r,*e;//r->free_number 用于查找空闲区的块数

office *q,*s,*t,*u;//s 创建新节点,存储新建文件的信息,n用于查找是否有

重复节点

p=w->p; r=p; q=w->q; t=q; u=q->next;

printf(\请输入文件名和块数:\s=(office*)malloc(sizeof(office)); s->next=NULL; while(t->next!=NULL)

t=t->next;

scanf(\while(u!=NULL){

if(strcmp(s->office,u->office)==0){ }

flag=1;

printf(\对不起,该文件已存在!\\n\free(s); break;

u=u->next; }

if(flag==0){

13

while(r!=NULL){

if((r->free_number)>=(s->office_number))//用于查找空闲区中空闲

块数是否大于欲分配的块数

}

if(r==NULL){ } else{

t->next=s;

m=r->start_location;//空闲区的起始地址

s->begin_location=r->start_location;//作业从空闲区的起始地址开printf(\对不起,没有足够的空间分配失败!\\n\free(s);

break;

r=r->next;

始分配

r->start_location=r->start_location+s->office_number;//改变空

闲区空闲块数的起始地址

r->free_number=r->free_number-s->office_number;//改变空间区块

数的大小

n=(r->start_location-1);//新的空间区的起始地址-1 for(i=m;i<=n;i++)//模拟分配

WST[i]=1;

if(r->free_number==0){

if(p==r){//p==r说明内存中只有一个整块的空闲区 } else{

e=p;

while(e!=NULL){

14

free(r); p=NULL;

}

}

}

}

}

}

if(e->next==r)

break;

e=e->next;

e->next=r->next; free(r);

w->p=p; w->q=q; return w;

/********************************************* 回收空间操作

**********************************************/ work *delect(work *w,int WET[]){

char name[20]; int i;

free_link *p,*r,*t; office *q,*s,*e; p=w->p; r=p; t=p; q=w->q; s=q; e=q; s=s->next; if(s==NULL){

15

}

printf(\没有可以回收的文件!\\n\

else {

printf(\请输入文件名:\cin>>name; while(s!=NULL){ }

if(s==NULL){ } else{

cout<<\对不起没有找到相关文件!\\n\if(strcmp(s->office,name)==0)

break;

s=s->next;

if((WST[s->begin_location-1]==0&&WST[s->begin_location+s->office_numb

er]==1&&s->begin_location-1>=0)

||(WST[s->begin_location-1]==0&&s->begin_location+s->office_number==2

56&&s->begin_location-1>=0)){

while(r!=NULL){

if((r->start_location+r->free_number)==s->begin_location)

}

}

r->free_number=r->free_number+s->office_number;

break;

r=r->next;

if((WST[s->begin_location-1]==1&&WST[s->begin_location+s->office_numb

er]==0&&

s->begin_location+s->office_number<256)||(s->begin_location==0&&

WST[s->begin_location+s->office_number]==0&&s->begin_location+s->offi

16

ce_number<256)){

while(r!=NULL){

if((s->begin_location+s->office_number)==r->start_location)

}

r->start_location=r->start_location-s->office_number; r->free_number=r->free_number+s->office_number;

break;

r=r->next;

}if(WST[s->begin_location-1]==0&&WST[s->begin_location+s->office_numb

er]==0&&s->begin_location-1>=0&&s->begin_location+s->office_number<256){

while(r!=NULL){

if((s->begin_location+s->office_number)==r->start_location){

}

}

r=r->next;

t=r; break;

r->free_number=r->free_number+s->office_number+t->free_number;

}

free(t);

if((WST[s->begin_location-1]==1&&WST[s->begin_location+s->office_numb

er]==1&&s->begin_location-1>=0

&&s->begin_location+s->office_number<256)

||(s->begin_location==0&&WST[s->begin_location+s->office_number]==1&& s->begin_location+s->office_number<256)

||(WST[s->begin_location-1]==1&&s->begin_location+s->office_number==2

56&&s->begin_location-1>=0)

||(s->begin_location==0&&s->begin_location+s->office_number==256)){

t=(free_link*)malloc(sizeof(free_link)); t->next=NULL;

17


模拟实现用位示图法管理文件存储空间的分配与回收1(4).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:土木工程施工试题库及答案2011

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: