資源簡介
操作系統(tǒng)課程設計,采用固定分區(qū),用最佳適應算法實現(xiàn)管理內存分配與回收
代碼片段和文件信息
#include
#include
#define?LEN?sizeof(struct?jcb)
struct?jcb
{
int?num;//分區(qū)序號
int?start;//首地址
int?size;//大小
int?state;//狀態(tài)
int?end;//結束地址
struct?jcb?*next;
};
struct?jcb?*creat(void)
{
struct?jcb?*head;
struct?jcb?*j1*j2*j;
int?end_1;//記錄下一分區(qū)的首地址
j=(struct?jcb*)?malloc(LEN);
int?n=1;
head=NULL;
cout<<“請輸入第“< cin>>j->start?>>j->size?;
j->end?=j->start?+j->size-1?;
while(j->size?!=0)//大小為零則創(chuàng)建分區(qū)表結束
{
end_1=j->end?+1;
if(head==NULL)
{
head=j;j->next?=NULL;j->num?=n;j->state?=0;
}
j=(struct?jcb*)?malloc(LEN);
n++;
cout<<“請輸入第“< ????????cin>>j->size?;
if(j->size?==0)break;
????????j->start?=end_1?;
j->end=j->start?+j->size?;
j1?=?head;???
j2=j1->next?;
評論
共有 條評論