操作系统课程设计——动态异长分区的存储分配与回收算法(共15页).doc
《操作系统课程设计——动态异长分区的存储分配与回收算法(共15页).doc》由会员分享,可在线阅读,更多相关《操作系统课程设计——动态异长分区的存储分配与回收算法(共15页).doc(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
2、, 10 );print_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(
3、);/记录起始时间FREEAREA *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-star
4、t_address p-next-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 !
5、= NULL)if(p-next-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_add
6、ress + p-size) = (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_
7、address = start_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;/记录结束时间,并将运行时间存入对应
8、数组t2 = GetCycleCount();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-nex
9、t-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-next-start_address temp-start_addre
10、ss)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) = (p-next-start_address)p-size =
11、 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;/将空闲区按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
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 操作系统 课程设计 动态 分区 存储 分配 回收 算法 15
限制150内