动态分区分配存储管理系统Word下载.docx

上传人:b****5 文档编号:19060469 上传时间:2023-01-03 格式:DOCX 页数:26 大小:338KB
下载 相关 举报
动态分区分配存储管理系统Word下载.docx_第1页
第1页 / 共26页
动态分区分配存储管理系统Word下载.docx_第2页
第2页 / 共26页
动态分区分配存储管理系统Word下载.docx_第3页
第3页 / 共26页
动态分区分配存储管理系统Word下载.docx_第4页
第4页 / 共26页
动态分区分配存储管理系统Word下载.docx_第5页
第5页 / 共26页
点击查看更多>>
下载资源
资源描述

动态分区分配存储管理系统Word下载.docx

《动态分区分配存储管理系统Word下载.docx》由会员分享,可在线阅读,更多相关《动态分区分配存储管理系统Word下载.docx(26页珍藏版)》请在冰豆网上搜索。

动态分区分配存储管理系统Word下载.docx

就是否

首次适应算法:

循环首次适应算法

四、系统测试

程序运行实例如下:

输入界面,按要求输入:

五、结论

作业采用数组形式进行存储,起初想用数组模拟分区,但划分记录比较不易,时间空间复杂度较大,容易混乱,遂决定用链表形式模拟分区情况。

基本能运行符合要求,能模拟出动态分区过程及最终结果

六.源程序

#include<

stdio、h>

stdlib、h>

iostream、h>

windows、h>

#defineFree0

#defineUse1

#defineMAX_length100//最大内存空间为100MB

#defineMaxNumber100

intFreePartition[MaxNumber]={16,16,8,32,64,32,8,16,64};

//空闲分区

intProcessNeed[MaxNumber]={7,18,9,20,35,8};

//每个进程需求

intFirstPartition[MaxNumber];

//首次

intCycleFirstPartition[MaxNumber];

//循环

intPartitionNumber=9,ProcessNum=6;

//空闲分区数及进程数

boolv();

boolv()

{

intj;

cout<

<

"

首次适应算法"

endl;

//FirstPartitionMethod();

for(inti=0;

i<

ProcessNum;

i++)//进程

for(j=0;

j<

j++)//分区

{

if(FreePartition[j]>

=ProcessNeed[i])

{FirstPartition[i]=j;

FreePartition[j]-=ProcessNeed[i];

break;

}

//c_out(FirstPartition);

for(i=0;

i++)

FreePartition[i]<

"

;

//Beginning();

FreePartition[0]=16;

FreePartition[1]=16;

FreePartition[2]=8;

FreePartition[3]=32;

FreePartition[4]=64;

FreePartition[5]=32;

FreePartition[6]=8;

FreePartition[7]=16;

FreePartition[8]=64;

cout<

循环首次适应算法"

//CycleFirstPartitionMethod();

j=0;

i++)//进程

for(;

)//分区

{CycleFirstPartition[i]=j;

}

j++;

j=j%PartitionNumber;

//c_out(CycleFirstPartition);

CycleFirstPartition[i]<

return1;

}

//--------------作业结构体数组----------------------------

typedefstructJOB

intnum;

//作业号

intsize;

//作业大小

intctime;

//作业进入时间

intrtime;

//作业运行时间

intstate;

//作业状态

}Job;

typedefstructDuLNode

intID;

//分区号

intstart;

//开始地址

//大小

//0=尚未使用1=使用2=释放

structDuLNode*prior;

//前驱指针

structDuLNode*next;

//后即指针

}DuLNode,*DuLinkList;

//-------------------------------------------------------------------------------

intFirstfit(int);

//首次适应算法

intNext_fit(int);

//循环首次适应算法

voidshowJob(int);

//显示作业表

voidshowPartiton(DuLinkList);

//显示分区表

//-----------------------------------------------------------------------------

//---------------------------全局变量-------------------------------------------

intf;

Job*A;

//排序前

Job*a;

//排序后

Job*temp;

//-----------------------------功能函数-------------------------------------------

voiddelay()

for(intx=10000;

x>

0;

x--)

for(inty=1000;

y>

y--);

//--------------------------------------------------------------------------------

//------------------------初始化---------------------------------------------------

DuLinkListInitpartitionList(DuLinkList&

p)

p=(DuLinkList)malloc(sizeof(DuLNode));

//申请空间

if(!

exit(0);

p->

size=100;

//初始化大小

printf("

输入分区首地址:

);

scanf("

%d"

&

p->

start);

state=0;

//状态置空闲

ID=0;

next=NULL;

prior=NULL;

returnp;

//------------------------------------------------------------------------------

//-----------------------------输入函数---------------------------------------------

intPutin(int&

n)

inti;

Jobtemp;

请输入任务数目:

n);

a=(Job*)malloc(n*sizeof(Job));

A=(Job*)malloc(n*sizeof(Job));

n;

{

printf("

\n"

信息输入:

\n\n"

作业号:

scanf("

a[i]、num);

作业大小:

a[i]、size);

作业进入时间:

a[i]、ctime);

作业运行时间:

a[i]、rtime);

a[i]、state=0;

//默认状态为Free

A[i]=a[i];

for(intj=0;

j<

n;

j++)

for(i=j;

i++)

if(a[j]、ctime>

a[i]、ctime)

{

temp=a[j];

a[j]=a[i];

a[i]=temp;

}

//冒泡排序

freopen("

data、txt"

"

w"

stdout);

for(i=0;

i<

%d%d%d%d\n"

a[i]、num,a[i]、size,a[i]、ctime,a[i]、rtime);

fclose(stdout);

CON"

保存成功\n\n"

return1;

//----------------------------------------------------------------------------------------

//-----------------------------读文件-----------------------------------------------------

intorder(int&

Inputthenumberofthetask:

r"

stdin);

for(inti=0;

fclose(stdin);

//------------------------------------------------------------------------

//-------------------------显示分区-------------------------------

voidshowPartition(DuLinkListpl)

\n\t\t\t分区表\n"

\t---------------------------------------\n"

\t开始地址\t分区号\t大小状态\n"

while(pl)

\t%d\t\t%d\t%d\t"

pl->

start,pl->

ID,pl->

size);

if(pl->

state==0)

printf("

空闲\n"

state==1)

已分配\n"

pl=pl->

next;

//-------------------------------------------------------------------------

//---------------------------------回收函数---------------------------------

voidhuishou(DuLinkListpl3,DuLinkList&

pl)//pl3就是分区链表指针pl头

while(pl3)

if(pl3->

state==0)

if(pl3->

next&

&

pl3->

prior&

prior->

state==0&

next->

state==1)//

{

pl3->

size+=pl3->

size;

pl3->

start=pl3->

start;

if(pl3->

prior)

{

next=pl3;

//pl3与最前一个

prior=pl3->

prior;

//

}

else

//pl3指向空

pl=pl3;

pl3=pl;

//pl3与头

}

elseif(pl3->

state==1)

next)

pl3->

prior=pl3;

//建立新链表pl3与最后一个结点

next=pl3->

pl3->

//指向空

elseif(!

//pl3与最后

start=pl->

{

//pl3与最前

}

else

{pl3->

pl=pl3;

pl3=pl;

size=pl3->

size+pl3->

//指向头

pl3=pl3->

//--------------------------------------------------------------------------------------

//----------------------------------首次适应算法---------------------------------------

voidFirstfit(DuLinkListblock_first,intn)

intt=1;

intnum=n;

while(t&

num)

DuLinkListpl1=block_first,pl2,pl3=block_first;

时钟:

%d\n"

t);

DuLNode*p=block_first;

DuLNode*q=block_first;

for(intx=0;

x<

x++)

{if(t==a[x]、ctime+a[x]、rtime)

a[x]、state=2;

for(intm=0;

m<

m++)

if(t==a[m]、ctime+a[m]、rtime)

num-=1;

a[m]、state=2;

//0等待1装入2结束

while(q)

if(q->

ID==a[m]、num)//分区号等于作业号时

q->

state=Free;

//在作业完成时,作业号等于分区号时空闲

q=q->

showJob(n);

showPartition(block_first);

for(m=0;

if(a[m]、ctime==t)

{

a[m]、state=1;

printf("

作业:

%d开始运行,对其分配!

a[m]、num);

if(t==a[m]、ctime)

while(pl1&

(pl1->

state==1||pl1->

size<

a[m]、size))pl1=pl1->

if(pl1)

pl2=(DuLinkList)malloc(sizeof(DuLNode));

pl2->

start=pl1->

start+a[m]、size;

size=pl1->

size-a[m]、size;

if(pl2->

size>

5)

pl1->

size=a[m]、size;

pl

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

当前位置:首页 > 解决方案 > 其它

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1