欢迎来到淘文阁 - 分享文档赚钱的网站! | 帮助中心 好文档才是您的得力助手!
淘文阁 - 分享文档赚钱的网站
全部分类
  • 研究报告>
  • 管理文献>
  • 标准材料>
  • 技术资料>
  • 教育专区>
  • 应用文书>
  • 生活休闲>
  • 考试试题>
  • pptx模板>
  • 工商注册>
  • 期刊短文>
  • 图片设计>
  • ImageVerifierCode 换一换

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

    • 资源ID:8852751       资源大小:236KB        全文页数:15页
    • 资源格式: DOC        下载积分:20金币
    快捷下载 游客一键下载
    会员登录下载
    微信登录下载
    三方登录下载: 微信开放平台登录   QQ登录  
    二维码
    微信扫一扫登录
    下载资源需要20金币
    邮箱/手机:
    温馨提示:
    快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
    如填写123,账号就是123,密码也是123。
    支付方式: 支付宝    微信支付   
    验证码:   换一换

     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

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

    精选优质文档-倾情为你奉上/该文件所含代码是课设需要学生自己写的代码和补充的代码,包含部分需要修改的课程设计指导书中的代码,不包含不需修改的代码/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_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();/记录起始时间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->start_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 != 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_address + 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_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;/记录结束时间,并将运行时间存入对应数组t2 = GetCycleCount();if(time00 > t2 - t1)time00 = t2 - t1;if(time01 < t2 - t1)time01 = t2 - t1; LeaveCriticalSection(&CS_FREEAREA_LIST);/3.最佳适应分配算法的内存释放函数void BF_release_memory(int start_address,int size)EnterCriticalSection(&CS_FREEAREA_LIST);_int64 t1, t2;/记录该算法起止时间t1 = GetCycleCount();/记录起始时间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->start_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 != 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_address + 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;/将空闲区按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_list = 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_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(time10 > t2 - t1)time10 = t2 - t1;if(time11 < t2 - t1)time11 = t2 - t1; LeaveCriticalSection(&CS_FREEAREA_LIST);/4.最坏适应分配算法:内存释放函数void WF_release_memory(int start_address,int size)EnterCriticalSection(&CS_FREEAREA_LIST);_int64 t1, t2;/记录该算法起止时间t1 = GetCycleCount();/记录起始时间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->start_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;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->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;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由大到小排序,以便符合WF算法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_list = 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_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(time20 > t2 - t1)time20 = t2 - t1;if(time21 < t2 - t1)time21 = t2 - t1; LeaveCriticalSection(&CS_FREEAREA_LIST);/5.二维数组,用于存放各种算法所需的最长时间和最短时间_int64 time32 = ,0,0,0;/6.显示程序运行时间void display_time(int n)EnterCriticalSection(&CS_SCREEN);printf("最短时间:%ld纳秒n",timen0);printf("最长时间:%ld纳秒n",timen1);LeaveCriticalSection(&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_freearea_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的运行结果专心-专注-专业

    注意事项

    本文(操作系统课程设计——动态异长分区的存储分配与回收算法(共15页).doc)为本站会员(飞****2)主动上传,淘文阁 - 分享文档赚钱的网站仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知淘文阁 - 分享文档赚钱的网站(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    关于淘文阁 - 版权申诉 - 用户使用规则 - 积分规则 - 联系我们

    本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

    工信部备案号:黑ICP备15003705号 © 2020-2023 www.taowenge.com 淘文阁 

    收起
    展开