好文档 - 专业文书写作范文服务资料分享网站

操作系统实验五

天下 分享 时间: 加入收藏 我要投稿 点赞

暨南大学本科实验报告专用纸

一, 实验目的。

了解动态分区分配方式中使用的数据结构和分配算法,并进一步加深对动态扮区存储管理方式及其实现过程的理解。

二, 实验内容。

1分别实现首次适应算法和最佳适应算法的动态分区分配过程和回收过程。其中,空闲分区通过空闲区链进行管理;进行内存分配时,系统优先使用空闲区低端的空间。

2、假设初试状态下,可用的内存空间为640KB,并有下列的请求序列: 作业1申请 130KB 作业2申请 60KB 作业3申请 100KB 作业2释放 60KB 作业4申请 200KB 作业3释放 100KB 作业1释放 130KB 作业5申请 140KB 作业6申请 60KB 作业7申请 50KB 作业6释放 60KB

3、每次分配和回收后显示空闲内存分区链情况。

三, 实验源代码。

最佳适应算法: #include\#include\int i=1;//id

typedef struct mem {

int start; int end;

struct mem *next; }mem;

typedef struct work {

int id;

int size;//memsize int start;

struct work *next;

}work;

work* initwork(int size) {

work *head=(work *)malloc(sizeof(head)); head->id=i; head->start=1; head->size=size; head->next=NULL; return head; }

work* insertwork(work *head,int start,int size) { i++;

work *pi,*pb;//pi is the insert one ##pb is the point pi=(work*)malloc(sizeof(work)); pi->id=i;

pi->start=start; pi->size=size; pi->next=NULL;

if(head==NULL){head=pi;head->next=NULL;} pb=head;

while(pb->next!=NULL){pb=pb->next;} pb->next=pi; return head; }

mem *initmem(int size) {

mem *head=(mem*)malloc(sizeof(mem)); head->start=1; head->end=640; head->next=NULL; return head; }

mem *insertmem(mem *head,int start,int size) {

mem *pi,*pb,*pf; int pbsize; pb=head;

pbsize=pb->end-pb->start+1; pi=(mem*)malloc(sizeof(mem)); pi->start=start;

pi->end=size+start-1;

if(pb==NULL){head=pi;pi->next=NULL;}

else {

while(pi->start>pb->start&&pb->next!=NULL){pf=pb;pb=pb->next;}

if(pi->startstart) {

if(pb==head) {

head=pi;//头节点 pi->next=pb; }

else {

pf->next=pi;//其他位置 pi->next=pb; } } else {

pb->next=pi;

pi->next=NULL;//在表末插入 } }

//合并相邻的内存 pf=pb=head;

while(pb->next!=NULL) {

if(pf->end+2>pb->start) {

pf->end=pb->end; pf->next=pb->next; } pf=pb;

pb=pb->next; }

return head; }

int getstart(work*head,int size) {

work *pb;

pb=head;

while(pb!=NULL) {

if(pb->size==size) {

return pb->start; }

pb=pb->next; }

return 0; }

int alloc(mem *head,int size) {

mem *pb; pb=head; int a;

while(pb!=NULL) {

if(size<=(pb->end-pb->start+1)) {

a=pb->start;

pb->start=pb->start+size;

return a; }

pb=pb->next; }

return 0; }

work*free1(work *head,int size) {

work *pb,*pf;

while(head==NULL){printf(\pb=head;

while(pb->size!=size&&pb->next!=NULL) {

pf=pb; pb=pb->next; }

if(pb->size==size)

{

if(pb==head)head=pb->next; else pf->next=pb->next; } end:

return head; }

void printw(work *head) {

work *pb; pb=head;

while(pb!=NULL) {

printf(\ start size---->\\n\ printf(\ pb=pb->next; } }

void printm(mem *head) {

mem *pb; pb=head;

while(pb!=NULL) {

printf(\ end---->\\n\ printf(\ pb=pb->next; } }

void main() {

int wrec;//接收返回的地址 int mrec; mem *mhead;

mhead=initmem(640); work *whead;

//1

whead=initwork(130); wrec=alloc(mhead,130);

//2

操作系统实验五

暨南大学本科实验报告专用纸一,实验目的。了解动态分区分配方式中使用的数据结构和分配算法,并进一步加深对动态扮区存储管理方式及其实现过程的理解。二,实验内容。1分别实现首次适应算法和最佳适应算法的动态分区分配过程和回收过程。其中,空闲分区通过空闲区链进行管理;进行内存分配时,系统优先使用空闲区低端的空间。2、假
推荐度:
点击下载文档文档为doc格式
6h2gm3ieyv207lq1bbd16zh7s4eqd201d20
领取福利

微信扫码领取福利

微信扫码分享