下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、实用文档文案大全实验内容:模拟操作系统的主存分配,运用可变分区的存储管理算法设计主存分配和回收程序,并不实际启动装入作业。采用最先适应法、最佳适应法、最坏适应法分配主存空间。当一个新作业要求装入主存时,必须查空闲区表,从中找出一个足够大的空闲区。若找到的空闲区大于作业需要量,这是应把它分成二部分,一部分为占用区,加一部分又成为一个空闲区。当一个作业撤离时,归还的区域如果与其他空闲区相邻,则应合并成一个较大的空闲区,登在空闲区表中。运行所设计的程序,输出有关数据结构表项的变化和内存的当前状态。实验要求:详细描述实验设计思想、程序结构及各模块设计思路;详细描述程序所用数据结构及算法;明确给出测试用
2、例和实验结果;为增加程序可读性,在程序中进行适当注释说明;认真进行实验总结,包括:设计中遇到的问题、解决方法与收获等;实验报告撰写要求结构清晰、描述准确逻辑性强;【实验过程记录(源程序、测试用例、测试结果及心得体会等)】#in clude#in clude#defi ne NULL 0#define LEN1 sizeof(struct job)/ 作业大小#define LEN2 sizeof(struct idle)/ 空闲区单元大小#define LEN3 sizeof(struct allocate)/ 已分配区单元大小int SPACE=100;定义内存空间大小int 0RIGI=1
3、;定义内存起始地址struct job/定义作业int n ame;int size;int address;struct idle/定义空闲区int size;int address;struct idle *next;;struct allocate/定义已分配区实用文档文案大全int name;int size;int address;struct allocate *next;;struct idle *creatidle(void) 建立空闲表struct idle *head;struct idle *p1;p1= (struct idle*)malloc(LEN2);p1-siz
4、e=SPACE; p1-address=ORIGI;p1- next=NULL;head=p1;return(head);struct allocate *creatallocate(void) 建立已分配表struct allocate *head;head=NULL;return(head);struct job *creatjob(void) 建立作业struct job *p;p=(struct job*)malloc(LEN1);printf(请输入要运行的作业的名称与大小:n);scan f(%d%d,&p- name, &p-size);return(p);str
5、uct idle *in it1(struct idle *head,struct job *p) 首次适应算法分配内存struct idle *p0,*p1;struct job *a;a=p;p0=head;p 仁 p0;while(p0- next!=NULL&p0-sizesize)p0=p0 _n ext;if(p0-sizea-size)p0-size=p0-size-a-size;a-address=p0-address; pO-address=pO-address+a-size;实用文档文案大全elseprintf(” 无法分配 n”);return(head);str
6、uct idle *in it2(struct idle *head,struct job *p)struct idle *p0,*p1;struct job *a;a=p;p0=head;if(pO=NULL)printf(无法进行分配!n);while(pO- next!=NULL&pO-sizesize)pO=pO _n ext;if(p0-sizea-size)p 仁 p0; pO=pO _n ext;elseprintf(无法分配!n);while(pO!=NULL)if(p0-sizep1-size)pO=pO _n ext;else if(p0-sizesize )&am
7、p;(pO-sizea-size)p 仁 p0; pO=pO _n ext; p1_size=(p1_size)_(a_size);a-address=p1-address;p1-address=(p1-address)+(a-size);return(head);最优实用文档文案大全struct idle *in it3(struct idle *head,struct job *p)/ 最差struct idle *p0,*p1;struct job *a;a=p;p0=head;if(pO=NULL)printf(无法进行分配!);while(pO- next!=NULL&pO-
8、sizesize)pO=pO _n ext;if(p0-sizea-size)p 仁 p0;pO=pO _n ext;elseprintf(无法分配!n”);while(p0!=NULL)if(p0-sizesize)pO=pO _n ext;else if(p0-sizep1-size)p 仁 p0;pO=pO _n ext;p1_size=(p1_size)_(a_size);a-address=p1-address;p1-address=(p1-address)+(a-size);return(head);struct allocate *reallocate(struct alloca
9、te *head,struct job *p)/ 重置已分配表struct allocate *pO,*p1,*p2;*p3,*p4;struct job *a;实用文档文案大全/struct idle *b;a=p;pO=(struct allocate*)malloc(LEN3);p1= (struct allocate*)malloc(LEN3);if(head=NULL)pO-n ame=a-n ame;pO-size=a-size;pO-address=ORIGI;p0- next=NULL;head=p0;Elsep1- n ame=a-n ame;p1-size=a-size;p
10、1-address=a-address;p2=head;while(p2- next!=NULL)p2=p2-n ext; p2-n ext=p1;p1- next=NULL;return(head);struct allocate *del(struct allocate *head,struct job *p) 删除指定的作业 struct job *p1;struct allocate *p2,*p3;p2=head;p 仁 p;while(p1- name!=p2- name) &(p2- next!=NULL)p3=p2;p2=p2-n ext;if(p1- n ame=p2
11、-n ame)if(p2=head)head=p2-n ext;elsep3-n ext=p2-n ext; return(head);struct job *delejob(struct allocate *head)实用文档文案大全struct job *p1;struct allocate *p2;int num;p1= (struct job*)malloc(LEN1);printf(请输入要删除的作业的名称n);scan f(%d,&n um);p2=head;while( nu m!=p2- name )&(p2- next!=NULL)p2=p2-n ext;if
12、(num=p2-n ame)p1- n ame=p2-n ame;p1-size=p2-size;p1-address=p2-address;return(p1);struct idle *un ite(struct job *p,struct idle *head) 合并相邻内存空间 struct idle *p1,*p2,*p3;struct job *m;m=p;p 仁 head;p3=(struct idle*)malloc(LEN2);while(p1-addressaddress)&(p1- next!=NULL)p2=p1;p1=p1- n ext;if(m-addres
13、saddress)if(head=p1)p3-size=m-size; p3-address=m-address;if(p1-address-p3-address)=(p3-size)p1-address=p3-address; p1-size=p3-size+p1-size;elsehead=p3;p3-n ext=p1;实用文档文案大全elsep3-size=m-size;p3-address=m-address;if(p1-address-p3-address)=(p3-size)p1-address=p3-address; p1-size=p3-size+p1-size;if(p3-a
14、ddress-p2-address)=(p2-size) p2-size=p1-size+p2-size;p2-n ext=p1- n ext;elsep2-n ext=p1;else if(p3-address-p2-address)=(p2-size) p2-size=p2-size+p3-size;elsep3-n ext=p1;p2-n ext=p3;elsep3-size=m-size;p3-address=m-address;if(p3-address-p1-address)=(p1-size) p1-size=p1-size+p3-size;elsep1- n ext=p3;p3
15、- next=NULL;return(head);void print(struct idle *h1,struct allocate *h2)实用文档文案大全struct idle *m1;struct allocate *n1;m1= h1;n 仁 h2;if(m1=NULL)printf(”空闲表为空!n);elsewhile(m1!=NULL)printf(空闲单元地址为 %d,其大小为dn,m1-address,m1-size); m1=m1- n ext;if(n 1=NULL)printf(已分配表为空!n);elsewhile( n1!=NULL)prin tf(已分配单元地址
16、为%d,其大小为%d,其名称 为dn ”, n1-address ,n1-size ,n1-n ame);n 仁 n1-n ext;void FF(void)struct idle *p1;struct allocate *p2;struct job *p,*q;int y=1;int n=0;int a=1;int c;p1=creatidle();p2=creatallocate();printf(初始情况为:n);prin t(p1,p2);while(a=y)实用文档文案大全printf(请输入要进行的操作:1.建立作业 2删除作业 3.结束操作n);scan f(%d, &c
17、);switch(c)case 1:p=creatjob();p1=in it1(p1,p);p2=reallocate(p2,p);prin t(p1,p2);break;case 2:q=delejob(p2);p2=del(p2,q);p2=reallocate(p2,q);p1= un ite(q,p1);prin t(p1,p2);break;case 3:y=0;break;void BF(void)struct idle *p1;struct allocate *p2;struct job *p,*q;int y=1;int n=0;int a=1;int c;p1=creati
18、dle();p2=creatallocate();printf(初始情况为:n);prin t(p1,p2);while(a=y)printf(请输入要进行的操作:1.建立作业 2删除作业 3.结束操作n);scan f(%d, &c);switch(c)case 1:p=creatjob();p1=i ni t2(p1,p);p2=reallocate(p2,p);prin t(p1,p2);break;实用文档文案大全case 2:q=delejob(p2);p2=del(p2,q);p2=reallocate(p2,q);p1= un ite(q,p1);prin t(p1,p2);break;case 3:y=0;break;void WF(void)struct idle *p1;struct allocate *p2;struct job *p,*q;int y=1;int n=0;int a=1;int c;p1=creatidle();p2=creatallocate();printf(初始情况为:n);prin t(p1,p2);while(a=y)printf(请输入要进行的操作:1.建立作业 2删除作业 3.结束操作n);scan f(%d, &c);switch(c)case 1:p=cr
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 有趣的语言水平测试题及答案
- 林业营林员相关试题及答案解析
- 福鼎时代面试考题及对应答案
- 2025-2026学年施秉县四下数学期中质量跟踪监视模拟试题含答案解析
- 2025-2026学年成都市新津县四下数学期中监测模拟试题(含答案解析)
- 硫化物相关试题及答案解析
- 株洲外国语测评试题及答案解析
- 2025-2026学年广东省江门市蓬江区荷塘雨露学校四年级数学第二学期期末达标检测试题含答案
- (新)医院重大事项请示报告制度
- 400道酸碱试题及精准答案解析
- 2026广东中山大学中山眼科中心茂名医院(茂名市眼科医院)招聘54人笔试模拟试题及答案详解
- 2026年秋季会计学专业开学第一课 专业认知与学业规划讲座方案
- 中国融通资源开发集团有限公司面向退役军人专项招聘100人笔试模拟试题及答案详解
- 康复护理扩容提升工程技术方案
- 基层医疗卫生机构慢性病健康管理中心建设与服务指南(2026年)
- 煤矿井下无轨胶轮车安全管理培训
- 中国利口酒行业市场发展现状及前景趋势与投资研究报告
- 2026年广东省中考数学试卷(含详细答案解析)
- 2026年江苏省自考06187农业概论高频考点重点串讲
- 2026中国商业遥感卫星数据定价策略与政府采购偏好研究
- 质量意识教育培训方案范文
评论
0/150
提交评论