操作系统实验四存储管理.doc_第1页
操作系统实验四存储管理.doc_第2页
操作系统实验四存储管理.doc_第3页
操作系统实验四存储管理.doc_第4页
操作系统实验四存储管理.doc_第5页
已阅读5页,还剩5页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

集美大学计算机工程学院实验报告课程名称:操作系统班级:计算1014指导教师:李传目姓名:林升仁实验项目编号:实验四学号:2010810116实验项目名称:存储管理实验成绩:一、目的理解动态异长存储分区资源管理,掌握所需数据结构和管理程序,了解各种存储分配算法的优点和缺点。二、实验内容与设计思想分析UNIX最先适应(FF)存储分配算法,即map数据结构、存储分配函数malloc()和存储释放函数mfree(),找出与算法有关的成分。 修改上述与算法有关的成分,使其分别体现BF分配原则和WF分配原则。 三、实验使用环境Red Hat Enterprise linux54、 实验结果源程序:/* * Copyright (C) 2004 by root * * rootsimplymepis * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */#ifdef HAVE_CONFIG_H#include #endif#include #include #define MAPSIZE 116struct map /存储资源表结构 /* char *m_size; char *m_addr; */ int m_addr; int m_size;struct map mapMAPSIZE; /存储资源表int FF_malloc(struct map *mp,int size) /存储分配函数 register int a,s; register struct map *bp,*bpp; for(bp = mp; bp-m_size; bp+) if (bp-m_size = size) a = bp-m_addr; s = bp-m_size; for(bpp = bp; bpp-m_size; bpp+)/最先适应 if(bpp-m_size = size & bpp-m_addrm_addr; s = bpp-m_size; bp = bpp; bp-m_addr += size; if (bp-m_size -=size) = 0) do bp+; (bp-1)-m_addr = bp-m_addr; while(bp-1)-m_size = bp-m_size); return(a); return(-1);void mfree(struct map *mp,int aa,int size) /存储释放函数 register struct map *bp; register int t; register int a; a = aa; for(bp = mp; bp-m_addrm_size != 0; bp+) ; if(bpmp & (bp-1)-m_addr+(bp-1)-m_size=a) /与前合并 (bp-1)-m_size += size; if (a+size = bp-m_addr) /前后合并 (bp-1)-m_size += bp-m_size; while (bp-m_size) bp+; (bp-1)-m_addr = bp-m_addr; (bp-1)-m_size = bp-m_size; else if (a+size = bp-m_addr & bp-m_size) /与后合并 bp-m_addr -= size; bp-m_size += size; else if (size) do /无合并 t = bp-m_addr; bp-m_addr = a; a = t; t = bp-m_size; bp-m_size = size; bp+; while (size = t); void init() struct map *bp; int addr,size; int i=0; bp=map; printf(Please input starting addr and total size:); scanf(%d,%d,&addr,&size); bp-m_addr=addr; bp-m_size=size; (+bp)-m_size=0; /表尾void show_map() int i=0; system(clear); /调用清屏命令 struct map *bp; bp=map; printf(nCurrent memory map.n); printf(AddressttSizen); while(bp-m_size!=0) printf(n,bp-m_addr,bp-m_size);bp+; printf(n);main() int a,s; int c; int i; init(); do /显示存储分配表 show_map(); printf(Please input, 1 for request,2 for release, 0 for exit:); scanf(%d,&c); switch(c) case 1: printf(Please input size:); scanf(%d, &s); if(a=FF_malloc(map,s)=-1) /call malloc printf(request cant be satisfiedn); else printf(alloc memory at address:%d,size:%dn,a,s); break; case 2: printf(Please input addr and size:); scanf(%d,%d,&a,&s); mfree(map,a,s); break; case 0: exit(0); while(1);运行结果:5、 实验分析上述算法沿用了UNIX系统所采用的数据结构,存储分配表中空闲区按m_addr递增排列,对于任意请求,需要由表头查到表尾才能确定最佳(最坏)分配区域。为提高存储分配时的查找速度,有人将表中空闲区按m_size递增(递减)排列,这样分配时取第一个长度能满足的表项即可。采用这种组织方式,不仅分配后剩余部分在表中的位置可能发生变化,而且需对释放函数进行较大的修改,试给出对应的算法 对于Lin

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论