#include<stdio.h>
#include<stdlib.h>
#define OK 1
#define ERROR 0
#define MEMSIZE 600
//定义地址分配
typedef struct Table
{
int num;
long address;
long length;
int state;
}ElemType;
//定义链表
typedef struct Node
{
ElemType data;
struct Node *prior;
struct Node *next;
}Node,*LinkList;
LinkList first;
LinkList end;
int flag;
//初始化链表
int Init()
{
first=(LinkList)malloc(sizeof(Node));
end=(LinkList)malloc(sizeof(Node));
first->prior=NULL;
first->next=end;
first->data.num=0;
first->data.address=0;
first->data.length=0;
first->data.state=1;
end->prior=first;
end->next=NULL;
end->data.num=1;
end->data.address=0;
end->data.length = MEMSIZE;
end->data.state=0;
return OK;
}
//显示分配情况
void show()
{
Node *p=first;
printf("--主存空间分配情况--\n");
printf("分区序号\t起始地址\t分区大小\t分区状态\n");
int nodeNum = 1;
while(p)
{
if (p->data.length == 0 || p->data.length < 0) {
p=p->next;
continue;
}
p->data.num = nodeNum;
printf("%d\t\t%ld\t\t%ld",p->data.num,p->data.address,p->data.length);
if(p->data.state==0) printf("\t\t空闲\n");
else printf("\t\t已分配\n");
p=p->next;
nodeNum++;
}
}
//首次适应算法
int First_fit(int request)
基于Linux的主存空间分配与回收
最新推荐文章于 2023-12-10 11:51:28 发布