连续空间存储管理模拟实验报告.docxVIP

  • 0
  • 0
  • 约5.79千字
  • 约 11页
  • 2024-04-11 发布于辽宁
  • 举报

连续空间存储管理模拟

实验报告

专业:计算机科学与技术(师范)

学号姓名:崔华俊

指导老师:张国强

2011-12-19

一、实验目的

掌握连续空间存储管理机制熟练运用linux的编译器

二、 实验内容

采用链表进行空闲区和已分配空间的管理

初始的内存大小为100000字节

采用最佳适应分配算法分配内存

功能键

a) 0退出

b) 1为作业分配内存

输入:作业名 要求的内存大小

执行逻辑:若无满足要求大小的空闲区,则显示无法分配的消息并退出,否则依据最佳适应分配算法找到空闲区,分配给作业(有可能需要对空闲区进行切割),并在已分配链表中进行登记

c) 2回收内存

输入:作业名

执行逻辑:在已分配链表中找到给定的作业名对应的项,将对应的内存回收,修改已分配链表和空闲区链表(有可能需要在空闲区链表中进行合并)

d) 3显示内存分配情况

已分配内存空间情况(作业名,起始地址,长度)和空闲区情况(起始地址,长度)

三、 实验步骤

#includeiostream

#includestdlib.h

usingnamespacestd;

structAllocatedSpace 〃已分配内存空间结构体

{

intstart_address;

intlength;

charjob;

structAllocatedSpace*next;

};

structFreeSpace //未分配内存空间结构体

{

intstart_address;

intlength;

structFreeSpace*next;

};

structAllocatedSpace*allocated_header;

structFreeSpace*free_header;

structFreeSpace*freenext;

voidallocatememory() //分配内存函数

{

charjobname;

intjoblength;

intmin,l=0;

cout请输入作业名(一个字母):\n;

cinjobname;

cout请输入作业长度(整数):\n;

cinjoblength;

structFreeSpace*w=free_header;

structFreeSpace*p=free_header; 〃指向第一个可以分配的空闲结点

p=p-next;

structFreeSpace*s=free_header; //指向p的前一个结点

structAllocatedSpace*t=allocated_header;

while(p-lengthjoblength) //p指向第一个可以分配的空结点

{

p=p-next;

if(p==NULL)

break;

}

if(p==NULL)

cout无法分配!\n;

else

{

w=p;

min=p-length-joblength;

while(p!=NULL) 〃现在p指向当前要被切割的结点

{

if(p-lengthjoblength)

l=p-length-joblength;

if(lmin)

{

w=p;

min=l;

}

p=p-next;

structAllocatedSpace*q=newAllocatedSpace;

q-job=jobname;

q-length=joblength;

q-start_address=w-start_address;

while(t-next!=NULL)

t=t-next;

q-next=t-next;

t-next=q;

while(s-next!=w)

s=s-next;

if(w-length==q-length)

{

s-next=w-next;

deletew;

}

else

{

w-start_address=w-start_address+q-length;

w-length=w-length-q-length;

}

}

}

voidreclaimmemory()

{

charjobname;

cout请输入要回收的作业名:\n;

cinjobname;

structFreeSpace*p=newstructFreeSpace;//指向当前被创建的空闲结点

structFreeSpace*s=free_header;//指p的前一个结点

structFreeSpace*m=free_header;//指向s的前一个结点

structAllocatedSpace*q=allocated_header;//指向被回收的结点

structAllocatedSpace*t=allocated_heade

文档评论(0)

1亿VIP精品文档

相关文档