当前位置: 首页 > news >正文

昆山企业网站建设公司品牌营销策划公司哪家好

昆山企业网站建设公司,品牌营销策划公司哪家好,做网站网站制作,那个网站是做副食批发一、实验目的: 实验目的: 通过编写一个内存分配模拟程序,实现首次适应算法(First Fit)、循环首次适应算法(Next Fit)、最佳适应算法(Best Fit)和最差适应算法&#xff08…

 

一、实验目的:

实验目的: 通过编写一个内存分配模拟程序,实现首次适应算法(First Fit)、循环首次适应算法(Next Fit)、最佳适应算法(Best Fit)和最差适应算法(Worst Fit),对比这些算法在内存管理中的性能表现,加深对内存分配策略的理解。

 

实验设备与实验环境:

计算机,Java编译系统,idea,ChatGPT

 

二、实验程序设计内容:

  1. 实现一个MemoryAllocation类,包含首次适应算法(firstFit())、循环首次适应算法(nextFit())、最佳适应算法(bestFit())和最差适应算法(worstFit())方法,以及打印内存状态的方法printMemory()。
  2. 在Main类中初始化一个内存空间,并通过MemoryAllocation类模拟不同的内存分配算法,输出内存分配结果,以及每种算法的性能表现。
  3. 通过比较不同算法的内存分配效果,总结各算法在实际应用中的优缺点,加深对内存管理策略的理解。

三、实验程序设计思路及流程图

  1. 在MemoryAllocation类中,实现首次适应算法、循环首次适应算法、最佳适应算法和最差适应算法的具体逻辑。
  2. 在Main类中,初始化内存空间并调用MemoryAllocation类中的不同算法方法,观察内存分配情况,并输出各算法的性能表现。
  3. 根据实验结果,分析不同算法的优缺点,理解各算法在不同场景下的适用性和性能表现。

 

四、实验源程序及注释:

package homework.os;/*** Date:2024/5/25  22:14* Description:mem allocation** @author Leon* @version 1.0*/class MemoryAllocation {private int[] memory;public MemoryAllocation(int memorySize) {memory = new int[memorySize];}public int firstFit(int processSize) {for (int i = 0; i < memory.length; i++) {int count = 0;int startIndex = -1;if (memory[i] == 0) {startIndex = i;while (i < memory.length && memory[i] == 0 && count < processSize) {count++;i++;}if (count == processSize) {for (int j = startIndex; j < startIndex + processSize; j++) {memory[j] = 1;}return startIndex;}}}return -1;}public int nextFit(int processSize) {int startIndex = 0;for (int i = 0; i < memory.length; i++) {if (memory[i] == 0) {if (i - startIndex >= processSize) {for (int j = startIndex; j < startIndex + processSize; j++) {memory[j] = 1;}return startIndex;}} else {startIndex = i + 1;}}return -1;}public int bestFit(int processSize) {int bestFitIndex = -1;int minHoleSize = Integer.MAX_VALUE;int currentHoleSize = 0;for (int i = 0; i < memory.length; i++) {if (memory[i] == 0) {currentHoleSize++;} else {if (currentHoleSize >= processSize && currentHoleSize < minHoleSize) {bestFitIndex = i - currentHoleSize;minHoleSize = currentHoleSize;}currentHoleSize = 0;}}if (currentHoleSize >= processSize && currentHoleSize < minHoleSize) {bestFitIndex = memory.length - currentHoleSize;}if (bestFitIndex == -1) {return -1;}for (int i = bestFitIndex; i < bestFitIndex + processSize; i++) {memory[i] = 1;}return bestFitIndex;}public int worstFit(int processSize) {int worstFitIndex = -1;int maxHoleSize = 0;int currentHoleSize = 0;for (int i = 0; i < memory.length; i++) {if (memory[i] == 0) {currentHoleSize++;} else {if (currentHoleSize > maxHoleSize) {maxHoleSize = currentHoleSize;worstFitIndex = i - currentHoleSize;}currentHoleSize = 0;}}if (currentHoleSize > maxHoleSize) {maxHoleSize = currentHoleSize;worstFitIndex = memory.length - currentHoleSize;}if (worstFitIndex == -1) {return -1;}for (int i = worstFitIndex; i < worstFitIndex + processSize; i++) {memory[i] = 1;}return worstFitIndex;}public void printMemory() {for (int cell : memory) {System.out.print(cell + " ");}System.out.println();}
}public class exm7_MemoryAllocation {public static void main(String[] args) {MemoryAllocation memoryAllocation = new MemoryAllocation(20);System.out.println("First Fit:");System.out.println(memoryAllocation.firstFit(3));memoryAllocation.printMemory();System.out.println("Next Fit:");System.out.println(memoryAllocation.nextFit(4));memoryAllocation.printMemory();System.out.println("Best Fit:");System.out.println(memoryAllocation.bestFit(5));memoryAllocation.printMemory();System.out.println("Worst Fit:");System.out.println(memoryAllocation.worstFit(2));memoryAllocation.printMemory();}
}

 

五、实验程序测试过程及解释说明

调用Main方法分别对四个内存分配算法进行调试

 

六、实验程序测试过程与结果分析、

First Fit:

0

1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Next Fit:

3

1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0

Best Fit:

7

1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0

Worst Fit:

12

1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0

 

Process finished with exit code 0

 

七、理论学习与实践能力锻炼方面的个人心得体会

通过本次实验,我深入了解了首次适应算法、循环首次适应算法、最佳适应算法和最差适应算法在内存分配中的应用和性能特点。观察实验结果可以发现,不同算法在内存分配中的表现有所差异,例如,最佳适应算法可以更好地利用碎片空间,而最差适应算法可能造成更多的碎片等。通过比较不同算法的表现,我对内存管理中不同的分配策略有了更深入的理解,为进一步学习和研究操作系统提供了有益的参考。

 

 

                

实验评价及结论:

 

实验目的明确、设计内容符合要求,独立完成了操作系统存储器管理的内存分配算法程序设计任务且源程序与注释、测试过程记录完整正确,能够很好地将课程理论运用于解决实际问题;实验报告内容完整,态度认真,总体质量优秀。

 

 

 

实验指导老师签字:                                   2024年    月    日

 

 

 

http://www.hkea.cn/news/705260/

相关文章:

  • 西安做网站优化的公司石家庄seo按天扣费
  • 2022年西安封城通知自动app优化下载
  • 无锡做网站哪家公司好一个公司可以做几个百度推广
  • 专题网站建设工作关键词林俊杰无损下载
  • adobe 网站开发软件软文写作兼职
  • 英文网站建设 淮安免费培训网站
  • 隔离需要多少钱湖南网站seo找行者seo
  • wordpress简单企业站seo怎么刷排名
  • 网站建设与运维泉州全网推广
  • 网站建站哪个公司好一点营销咨询服务
  • 值得玩的网页游戏北京seo营销培训
  • 中国建设银行网站分期通百度推广登录平台网址
  • 公司内部网站源码新闻软文推广案例
  • vf建设银行网站谷歌seo排名
  • 如何申请商业服务器武汉seo工厂
  • 祥云平台英文网站微博指数查询入口
  • 公司网站建设准备资料今日重大财经新闻
  • 发布网站后备案免费网站建站页面
  • 浙江建设职业技术学院迎新网站做一个网站要多少钱
  • axure做网站好不好手机百度问一问
  • 开发微信小程序的流程广州seo优化电话
  • 小企业网站建设和管理全能搜
  • 无棣县建设局网站游戏优化大师下载安装
  • 小额贷款 网站模板品牌推广软文
  • 网站建设开发成本天津百度搜索网站排名
  • 做的好的营销型网站有哪些内容外贸网站外链平台
  • 东营网站建设预算价格百度网盘网页版入口官网
  • 网站建设中标公告18款禁用看奶app入口
  • 网站运营人员岗位职责长沙正规seo优化价格
  • cnzz统计代码放在后台网站为什么没显示seo的英文全称是什么