实验四存储器管理系统文档格式.docx

上传人:b****2 文档编号:618763 上传时间:2023-04-29 格式:DOCX 页数:16 大小:39.37KB
下载 相关 举报
实验四存储器管理系统文档格式.docx_第1页
第1页 / 共16页
实验四存储器管理系统文档格式.docx_第2页
第2页 / 共16页
实验四存储器管理系统文档格式.docx_第3页
第3页 / 共16页
实验四存储器管理系统文档格式.docx_第4页
第4页 / 共16页
实验四存储器管理系统文档格式.docx_第5页
第5页 / 共16页
实验四存储器管理系统文档格式.docx_第6页
第6页 / 共16页
实验四存储器管理系统文档格式.docx_第7页
第7页 / 共16页
实验四存储器管理系统文档格式.docx_第8页
第8页 / 共16页
实验四存储器管理系统文档格式.docx_第9页
第9页 / 共16页
实验四存储器管理系统文档格式.docx_第10页
第10页 / 共16页
实验四存储器管理系统文档格式.docx_第11页
第11页 / 共16页
实验四存储器管理系统文档格式.docx_第12页
第12页 / 共16页
实验四存储器管理系统文档格式.docx_第13页
第13页 / 共16页
实验四存储器管理系统文档格式.docx_第14页
第14页 / 共16页
实验四存储器管理系统文档格式.docx_第15页
第15页 / 共16页
实验四存储器管理系统文档格式.docx_第16页
第16页 / 共16页
亲,该文档总共16页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

实验四存储器管理系统文档格式.docx

《实验四存储器管理系统文档格式.docx》由会员分享,可在线阅读,更多相关《实验四存储器管理系统文档格式.docx(16页珍藏版)》请在冰点文库上搜索。

实验四存储器管理系统文档格式.docx

程序运行的流程如下图:

5.实验运行情况

****************MENU***************

Youcanselectoneofthefollowing:

(1)Requiretobeallocate.请分配内存

(2)Requiretocollectethesize.将分配的内存回收

(3)Checkthememory.检查当前的内存情况

(4)Quit.退出

***********************************

1

Enteryourjobname:

JOB1

Enteryourjoblength:

1000

namelength(b)addre

JOB110002000

Thetotalleftis4000bytes

6.实验程序

#include<

stdio.h>

dos.h>

stdlib.h>

conio.h>

io.h>

#include"

string.h"

#defineTOTALSPACE5000/*起始空闲空间大小

#defineINITADDRESS2000/*起始地址

#defineMINSPACE100

#defineMAXJOBCNT10/*内存中作业数量最大值

structJobMat

{

charname[10];

intaddress;

intlength;

structJobMat*next;

structJobMat*back;

};

structFreeArea

intsize;

structFreeArea*next;

structFreeArea*back;

structJobMat*p_JobMat;

structFreeArea*p_FreeArea;

intUnusedSpace;

/*未分配的空闲空间大小

intCurrentJobCnt;

/*目前内存中的作业数量

intJobSize;

/*目前要分配的作业的大小

charJobName[10];

intJobAddress;

voidinitiation(){

p_FreeArea=(structFreeArea*)malloc(sizeof(structFreeArea));

p_FreeArea->

size=TOTALSPACE;

address=INITADDRESS;

next=NULL;

back=NULL;

UnusedSpace=TOTALSPACE;

p_JobMat=NULL;

CurrentJobCnt=0;

JobSize=0;

memset(JobName,0,10);

JobAddress=0;

}

voidffallocation()

structFreeArea*fp;

structJobMat*jp;

structJobMat*jp1;

structJobMat*jp2;

JobAddress=-1;

if(UnusedSpace<

JobSize)

{

/*printf("

Sorry,youinputjoblengthistoobig^_^\n"

);

*/

return;

}

fp=p_FreeArea;

while(fp!

=NULL)

if((fp->

size)<

JobSize)

{

fp=fp->

next;

}

else

CurrentJobCnt=CurrentJobCnt+1;

UnusedSpace=UnusedSpace-JobSize;

jp2=(structJobMat*)malloc(sizeof(structJobMat));

strcpy(jp2->

name,JobName);

jp2->

length=JobSize;

address=fp->

address;

JobAddress=jp2->

if(p_JobMat==NULL)

{

jp2->

p_JobMat=jp2;

}

else

jp=p_JobMat;

while((jp!

=NULL)&

&

(jp2->

address<

jp->

address))

{

jp1=jp;

jp=jp->

}

next=jp;

if(jp==NULL)

jp2->

back=jp1;

jp1->

next=jp2;

back=jp->

back;

if(jp->

back!

=NULL)jp1->

elsep_JobMat=jp2;

jp->

back=jp2;

if(fp->

size-JobSize<

MINSPACE)

if(fp->

next!

=NULL)fp->

next->

back=fp->

back->

next=fp->

elsep_FreeArea=fp->

fp->

size=fp->

size-JobSize;

address+JobSize;

/*exit

(1);

voidffcollection()

structFreeArea*fp;

structFreeArea*fp1;

structFreeArea*fp2;

intf;

jp=p_JobMat;

f=0;

while((jp!

=NULL)&

strcmp(jp->

name,JobName)!

=0)

jp=jp->

if(jp!

CurrentJobCnt=CurrentJobCnt-1;

UnusedSpace=UnusedSpace+jp->

length;

if(p_FreeArea==NULL)

p_FreeArea=(structFreeArea*)malloc(sizeof(structFreeArea));

p_FreeArea->

address=jp->

size=jp->

fp=p_FreeArea;

while((fp!

(fp->

fp1=fp;

fp=fp->

if(fp!

if((fp->

address==jp->

address+jp->

length))

f=f+1;

(jp->

address==fp1->

address+fp1->

size))

f=f+2;

elseif((jp->

address)==(fp1->

address+(fp1->

size)))

f=f+2;

switch(f)

case0:

fp2=(structFreeArea*)malloc(sizeof(structFreeArea));

fp2->

next=fp;

if(fp!

{

fp2->

if(fp->

=NULL)fp1->

next=fp2;

elsep_FreeArea=fp2;

fp->

back=fp2;

}

else

back=fp1;

fp1->

break;

case1:

fp->

size+jp->

case2:

fp1->

size=fp1->

case3:

length+fp->

size;

if(fp->

free(fp);

if(jp==p_JobMat)p_JobMat=jp->

if(jp->

=NULL){jp->

=NULL)jp->

next=jp->

free(jp);

voidshowyou()

/*clrscr();

if(CurrentJobCnt<

=0)

printf("

Nojob.\n"

else

namelength(b)addre\n"

jp=p_JobMat;

while(jp!

printf("

%s%d%d\n"

jp->

name,jp->

length,jp->

address);

jp=jp->

printf("

Thetotalleftis%dbytes\n"

UnusedSpace);

voidcoalesce()

intbottom;

if(CurrentJobCnt>

0)

bottom=TOTALSPACE+INITADDRESS;

jp->

address=bottom-jp->

bottom=bottom-jp->

fp=p_FreeArea;

while(fp!

fp1=fp;

free(fp1);

p_FreeArea=(structFreeArea*)malloc(sizeof(structFreeArea));

p_FreeArea->

size=UnusedSpace;

voidmenu()

intselect;

\n\n\n****************MENU***************\n"

\n"

(1)Requiretobeallocate.\n"

(2)Requiretocollectethesize.\n"

(3)Checkthememory.\n"

(4)Quit.\n"

***********************************\n"

scanf("

%d"

&

select);

switch(select)

case1:

if(CurrentJobCnt>

=MAXJOBCNT)

printf("

Thejobistoomany"

"

scanf("

%s"

JobName);

JobSize);

ffallocation();

switch(JobAddress)

case-1:

printf("

thememoryisfull"

coalesce();

ffallocation();

default:

break;

case2:

Enterthenameofjob:

ffcollection();

case3:

case4:

exit

(1);

default:

Youinputawrongnumber!

voidmain()

initiation();

while

(1)

menu();

showyou();

7.实验结果

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 工程科技 > 能源化工

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2