收藏 分销(赏)

操作系统课程设计——动态异长分区的存储分配与回收算法.doc

上传人:Fis****915 文档编号:554585 上传时间:2023-12-08 格式:DOC 页数:15 大小:270KB
下载 相关 举报
操作系统课程设计——动态异长分区的存储分配与回收算法.doc_第1页
第1页 / 共15页
操作系统课程设计——动态异长分区的存储分配与回收算法.doc_第2页
第2页 / 共15页
操作系统课程设计——动态异长分区的存储分配与回收算法.doc_第3页
第3页 / 共15页
操作系统课程设计——动态异长分区的存储分配与回收算法.doc_第4页
第4页 / 共15页
操作系统课程设计——动态异长分区的存储分配与回收算法.doc_第5页
第5页 / 共15页
点击查看更多>>
资源描述

1、/该文件所含代码是课设需要学生自己写的代码和补充的代码,包含部分需要修改的课程设计指导书中的代码,不包含不需修改的代码/1.显示空闲区表void display_freearea_list() FREEAREA *p;char buffer20; p=p_free_area_list;printf(|-|-|n);printf(| start_address(kB) | size(KB) |n);printf(|-|-|n);while(p!=NULL)printf(| %d,p-start_address);itoa( p-start_address, buffer, 10 );print_

2、space(19-strlen(buffer);printf(| %d,p-size);itoa(p-size, buffer, 10 );print_space(17-strlen(buffer);printf(|n);p=p-next; printf(|-|-|nn);/2.最先适应分配法:内存释放函数void FF_release_memory(int start_address,int size)EnterCriticalSection(&CS_FREEAREA_LIST);_int64 t1, t2;/记录该算法起止时间t1 = GetCycleCount();/记录起始时间FREE

3、AREA *temp,*p,*pp;/将空闲区按start_address由小到大排序,以便整合相邻空闲区while(1)int change = 0;p = p_free_area_list;if(p-next != NULL)if(p-start_address p-next-start_address)pp = p-next;p-next = pp-next;pp-next = p;p_free_area_list = pp;change = 1;if(p-next != NULL)while(p-next-next != NULL)if(p-next-start_address p-n

4、ext-next-start_address )pp = p-next-next;p-next-next = pp-next;pp-next = p-next;p-next = pp;change = 1;p = p-next ;if(change = 0)break;/插入空闲区temp = new FREEAREA;p = new FREEAREA;temp-start_address = start_address;temp-size = size;temp-next = NULL;p-next = p_free_area_list;while(p-next != NULL)if(p-n

5、ext-start_address temp-start_address)temp-next = p-next ;p-next = temp;break;elsep = p-next ;if(p-next = NULL)p-next = temp;else if(temp-next = p_free_area_list)p_free_area_list = temp;/整合碎片while(1)int change = 0;p = p_free_area_list;if(p = NULL)break;while(p-next != NULL)if(p-start_address + p-size

6、) = (p-next-start_address)p-size = p-next-size + p-size;change = 1; if(p-next-next = NULL)free(p-next);p-next = NULL;elsep-next = p-next-next;if(p-next = NULL)break;elsep = p-next ;if(change = 0)break;/整理线程结束后的驻留链表THREAD_RESIDENCE_MEMORY *q;q = p_thread_residence_memory_list;if(q-start_address = sta

7、rt_address)p_thread_residence_memory_list = p_thread_residence_memory_list-next ;elsewhile(q-next != NULL)if(q-next-start_address = start_address)if(q-next = tail_thread_residence_memory_list)tail_thread_residence_memory_list = q;q-next = q-next-next ;break;q = q-next;/记录结束时间,并将运行时间存入对应数组t2 = GetCyc

8、leCount();if(time00 t2 - t1)time00 = t2 - t1;if(time01 next != NULL)if(p-start_address p-next-start_address)pp = p-next;p-next = pp-next;pp-next = p;p_free_area_list = pp;change = 1;if(p-next != NULL)while(p-next-next != NULL)if(p-next-start_address p-next-next-start_address )pp = p-next-next;p-next

9、-next = pp-next;pp-next = p-next;p-next = pp;change = 1;p = p-next ;if(change = 0)break;/插入空闲区temp = new FREEAREA;p = new FREEAREA;temp-start_address = start_address;temp-size = size;temp-next = NULL;p-next = p_free_area_list;while(p-next != NULL)if(p-next-start_address temp-start_address)temp-next

10、= p-next ;p-next = temp;break;elsep = p-next ;if(p-next = NULL)p-next = temp;else if(temp-next = p_free_area_list)p_free_area_list = temp;/整合碎片while(1)int change = 0;p = p_free_area_list;if(p = NULL)break;while(p-next != NULL)if(p-start_address + p-size) = (p-next-start_address)p-size = p-next-size

11、+ p-size;change = 1; if(p-next-next = NULL)free(p-next);p-next = NULL;elsep-next = p-next-next;if(p-next = NULL)break;elsep = p-next ;if(change = 0)break;/将空闲区按SIZE由小到大排序,以便符合BF算法while(1)int change = 0;p = p_free_area_list;if(p-size p-next-size)pp = p-next;p-next = pp-next;pp-next = p;p_free_area_li

12、st = pp;change = 1;while(p-next-next != NULL)if(p-next-size p-next-next-size )pp = p-next-next;p-next-next = pp-next;pp-next = p-next;p-next = pp;change = 1;p = p-next ;if(change = 0)break;/整理线程结束后的驻留链表THREAD_RESIDENCE_MEMORY *q;q = p_thread_residence_memory_list;if(q-start_address = start_address)p

13、_thread_residence_memory_list = p_thread_residence_memory_list-next ;elsewhile(q-next != NULL)if(q-next-start_address = start_address)if(q-next = tail_thread_residence_memory_list)tail_thread_residence_memory_list = q;q-next = q-next-next ;break;q = q-next;/记录结束时间,并将运行时间存入对应数组t2 = GetCycleCount();if

14、(time10 t2 - t1)time10 = t2 - t1;if(time11 next != NULL)if(p-start_address p-next-start_address)pp = p-next;p-next = pp-next;pp-next = p;p_free_area_list = pp;change = 1;if(p-next != NULL)while(p-next-next != NULL)if(p-next-start_address p-next-next-start_address )pp = p-next-next;p-next-next = pp-n

15、ext;pp-next = p-next;p-next = pp;change = 1;p = p-next ;if(change = 0)break;/插入空闲区temp = new FREEAREA;temp-start_address = start_address;temp-size = size;temp-next = NULL;p = new FREEAREA;p-next = p_free_area_list;while(p-next != NULL)if(p-next-start_address temp-start_address)temp-next = p-next ;p-

16、next = temp;break;elsep = p-next ;if(p-next = NULL)p-next = temp;else if(temp-next = p_free_area_list)p_free_area_list = temp;/整合碎片while(1)int change = 0;p = p_free_area_list;if(p = NULL)break;while(p-next != NULL)if(p-start_address + p-size) = (p-next-start_address)p-size = p-next-size + p-size;cha

17、nge = 1; if(p-next-next = NULL)free(p-next);p-next = NULL;elsep-next = p-next-next;if(p-next = NULL)break;elsep = p-next ;if(change = 0)break;/将空闲区按SIZE由大到小排序,以便符合WF算法while(1)int change = 0;p = p_free_area_list;if(p-size next-size)pp = p-next;p-next = pp-next;pp-next = p;p_free_area_list = pp;change

18、 = 1;while(p-next-next != NULL)if(p-next-size next-next-size )pp = p-next-next;p-next-next = pp-next;pp-next = p-next;p-next = pp;change = 1;p = p-next ;if(change = 0)break;/整理线程结束后的驻留链表THREAD_RESIDENCE_MEMORY *q;q = p_thread_residence_memory_list;if(q-start_address = start_address)p_thread_residenc

19、e_memory_list = p_thread_residence_memory_list-next ;elsewhile(q-next != NULL)if(q-next-start_address = start_address)if(q-next = tail_thread_residence_memory_list)tail_thread_residence_memory_list = q;q-next = q-next-next ;break;q = q-next;/记录结束时间,并将运行时间存入对应数组t2 = GetCycleCount();if(time20 t2 - t1)

20、time20 = t2 - t1;if(time21 t2 - t1)time21 = t2 - t1; LeaveCriticalSection(&CS_FREEAREA_LIST);/5.二维数组,用于存放各种算法所需的最长时间和最短时间_int64 time32 = 99999999,0,99999999,0,99999999,0;/6.显示程序运行时间void display_time(int n)EnterCriticalSection(&CS_SCREEN);printf(最短时间:%ld纳秒n,timen0);printf(最长时间:%ld纳秒n,timen1);LeaveCri

21、ticalSection(&CS_SCREEN);/7.在FF()、BF()、WF()中的删除各链表操作前加入以下代码void FF()/显示线程结束后的空闲区EnterCriticalSection(&CS_SCREEN);printf(空闲区:n);display_freearea_list();LeaveCriticalSection(&CS_SCREEN);/显示该算法所需时间display_time(0);/删除各种链表void BF()/显示线程结束后的空闲区EnterCriticalSection(&CS_SCREEN);printf(空闲区:n);display_freeare

22、a_list();LeaveCriticalSection(&CS_SCREEN);/显示该算法所需时间display_time(1);/删除各种链表void WF()/显示线程结束后的空闲区EnterCriticalSection(&CS_SCREEN);printf(空闲区:n);display_freearea_list();LeaveCriticalSection(&CS_SCREEN);/显示该算法所需时间display_time(2);/删除各种链表/8.设置计算时间的函数RDTSC方法_inline unsigned _int64 GetCycleCount() _asm _emit 0x0F _asm _emit 0x31/9.获取当前时间t = GetCycleCount();主界面:FF的运行结果BF的运行结果WF的运行结果

展开阅读全文
部分上传会员的收益排行 01、路***(¥15400+),02、曲****(¥15300+),
03、wei****016(¥13200+),04、大***流(¥12600+),
05、Fis****915(¥4200+),06、h****i(¥4100+),
07、Q**(¥3400+),08、自******点(¥2400+),
09、h*****x(¥1400+),10、c****e(¥1100+),
11、be*****ha(¥800+),12、13********8(¥800+)。
相似文档                                   自信AI助手自信AI助手
百度文库年卡

猜你喜欢                                   自信AI导航自信AI导航
搜索标签

当前位置:首页 > 教育专区 > 其他

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        获赠5币

©2010-2024 宁波自信网络信息技术有限公司  版权所有

客服电话:4008-655-100  投诉/维权电话:4009-655-100

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :gzh.png    weibo.png    LOFTER.png 

客服