主存空间的分配和回收,分全拿出来了

来源:百度知道 编辑:UC知道 时间:2024/06/19 08:33:00
struct program
{
char name[30];
long start;
long length;
struct program *next;
};

struct space
{
long start;
long length;
struct space *next;
};

space *L;
program *S;

void creat()
{
L=new space;
space *p=new space;
p->start=0;
p->length=128;
p->next=NULL;
L->next=p;
S=new program;
S->next=NULL;
}
void back()
{
char name[30];
cout<<"输入要回收的进程名:";
cin>>name;
program *p;
p=S;
while(p->next!=NULL)
{
if(strcmp(p->next->name, name)==0)
{
callback(p);
return;
}
p=p->next;
}
if(p->next==NULL)
cout<<"此进程不存在,内存回收失败"<<endl;

#include <iostream.h>
#include <stdio.h>
#include <string.h>

struct program
{
char name[30];
long start;
long length;
struct program *next;
};

struct space
{
long start;
long length;
struct space *next;
};

void creat();
void allot();
void back();
void callback(program *r);
void sort(space *L);
void sort(program *S);
void display(space *L);
void display(program *S);

space *L;
program *S;

void creat()
{
L=new space;
space *p=new space;
p->start=0;
p->length=128;
p->next=NULL;
L->next=p;
S=new program;
S->next=NULL;
}
void allot()
{
program *q;
q=new program;
cout<<"请输入进程名和占用空间大小:"<<endl;
cin>>q->name>>