• 大小: 18KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-09-04
  • 语言: 其他
  • 标签:

资源简介

可变分区调度算法有:最先适应分配算法,最优适应分配算法,最坏适应算法。 用户提出内存空间的申请;系统根据申请者的要求,按照一定的分配策略分析内存空间的使用情况,找出能满足请求的空闲区,分给申请者;当程序执行完毕或主动归还内存资源时,系统要收回它所占用的内存空间或它归还的部分内存空间。 每当一个进程被创建时,内存分配程序首先要查找空闲内存分区表(链),从中寻找一个合适的空闲块进行划分,并修改空闲内存分区表(链)。当进程运行完毕释放内存时,系统根据回收区的首址,从空闲区表(链)中找到相应的插入点,此时出现如下四种情况: 1) 回收区与插入点的前一个空闲分区F1相邻接,此时可将回收区直接与F1合并,并修改F1的大小; 2) 回收区与插入点的后一个空闲分区F2相邻接,此时可将回收区直接与F2合并,并用回收区的首址最为新空闲区的首址,大小为二者之和; 3) 回收区同时与插入点的前、后两个空闲分区邻接,此时需将三者合并; 4) 回收区不与任何一个空闲区邻接,此时应建一新的表项。

资源截图

代码片段和文件信息

package com.chengshijian.operatesystem;

import java.util.Scanner;

/**
 * Created by ChengShiJian on 2017/11/08.
 * 
 */

public class DynamicPartAllocate {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        System.out.println(“软件1503  程世健 1511030304“);
        final Scanner scanner = new Scanner(System.in);
        new DynamicPartAllocatePresenter().setOnExcuteLisenter(new OnExecuteLisenter() {
            @Override
            public Job getJob() {
                // TODO Auto-generated method stub
                while (true) {
                    System.out.print(“请输入作业(作业号   所用空间大小)>“);
                    Job job = new Job();
                    int id = scanner.nextInt();
                    if (id < 1) {
                        System.out.println(“作业号必须大于0!“);
                        continue;
                    }
                    int length = scanner.nextInt();
                    job.setJobId(id);
                    job.setLength(length);
                    return job;
                }
            }

            @Override
            public void onOutOfMemory() {
                // TODO Auto-generated method stub
                System.out.println(“磁盘空间不足!“);
            }

            @Override
            public void onAllocateSuccess(Partition partition) {
                // TODO Auto-generated method stub
                System.out.println(“----------------------------当前内存情况------------------------------“);
                System.out.println(
                        “起始地址                       终点地址                               内存大小                                  状态                        作业号“);

                for (PartBlock block : partition.getBlocks()) {
                    System.out.printf(“%-15d%-15d%-15d%-30s%-15s\n“ block.getStartAddress() block.getEndAddress()
                            block.getLength() block.getState() block.getJobId()==0?““:String.valueOf(block.getJobId()));
                }
                System.out.println(“------------------------------------------------------------------“);
            }

            @Override
            public int getJobId() {
                // TODO Auto-generated method stub
                System.out.print(“请输入作业id>“);
                return scanner.nextInt();
            }

            @Override
            public void onSearchError(int id) {
                // TODO Auto-generated method stub
                System.out.println(“作业“ + id + “不存在!回收内存失败!“);
            }

            @Override
            public void onRetrieveSuccess(Partition partition) {
                // TODO Auto-generated method stub
                System.out.println(“----------------------------当前内存情况------------------------------“);
                System.out.println(
                        “起始地址                       终点地址                               内存大小           

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件        301  2018-01-20 14:52  dynamicPartallocate\.classpath

     文件        395  2018-01-20 14:52  dynamicPartallocate\.project

     文件        598  2018-01-20 14:52  dynamicPartallocate\.settings\org.eclipse.jdt.core.prefs

     文件       4363  2018-01-20 14:59  dynamicPartallocate\bin\com\chengshijian\operatesystem\DynamicPartAllocate$1.class

     文件       1189  2018-01-20 14:59  dynamicPartallocate\bin\com\chengshijian\operatesystem\DynamicPartAllocate.class

     文件       1336  2018-01-20 14:57  dynamicPartallocate\bin\com\chengshijian\operatesystem\DynamicPartAllocatePresenter$1.class

     文件       1333  2018-01-20 14:57  dynamicPartallocate\bin\com\chengshijian\operatesystem\DynamicPartAllocatePresenter$2.class

     文件       1331  2018-01-20 14:57  dynamicPartallocate\bin\com\chengshijian\operatesystem\DynamicPartAllocatePresenter$3.class

     文件       5747  2018-01-20 14:57  dynamicPartallocate\bin\com\chengshijian\operatesystem\DynamicPartAllocatePresenter.class

     文件        686  2018-01-20 14:57  dynamicPartallocate\bin\com\chengshijian\operatesystem\Job.class

     文件        439  2018-01-20 14:58  dynamicPartallocate\bin\com\chengshijian\operatesystem\OnExecuteLisenter.class

     文件       1936  2018-01-20 14:57  dynamicPartallocate\bin\com\chengshijian\operatesystem\PartBlock.class

     文件       1528  2018-01-20 14:57  dynamicPartallocate\bin\com\chengshijian\operatesystem\Partition.class

     文件       4961  2018-01-20 14:59  dynamicPartallocate\src\com\chengshijian\operatesystem\DynamicPartAllocate.java

     文件       9741  2018-01-20 14:57  dynamicPartallocate\src\com\chengshijian\operatesystem\DynamicPartAllocatePresenter.java

     文件        492  2018-01-20 14:57  dynamicPartallocate\src\com\chengshijian\operatesystem\Job.java

     文件        623  2018-01-20 14:58  dynamicPartallocate\src\com\chengshijian\operatesystem\OnExecuteLisenter.java

     文件       1716  2018-01-20 14:57  dynamicPartallocate\src\com\chengshijian\operatesystem\PartBlock.java

     文件       1010  2018-01-20 14:57  dynamicPartallocate\src\com\chengshijian\operatesystem\Partition.java

     目录          0  2018-01-20 14:59  dynamicPartallocate\bin\com\chengshijian\operatesystem

     目录          0  2018-01-20 14:59  dynamicPartallocate\src\com\chengshijian\operatesystem

     目录          0  2018-01-20 14:59  dynamicPartallocate\bin\com\chengshijian

     目录          0  2018-01-20 14:59  dynamicPartallocate\src\com\chengshijian

     目录          0  2018-01-20 14:59  dynamicPartallocate\bin\com

     目录          0  2018-01-20 14:59  dynamicPartallocate\src\com

     目录          0  2018-01-20 14:59  dynamicPartallocate\.settings

     目录          0  2018-01-20 14:59  dynamicPartallocate\bin

     目录          0  2018-01-20 14:59  dynamicPartallocate\src

     目录          0  2018-01-20 14:59  dynamicPartallocate

----------- ---------  ---------- -----  ----

............此处省略2个文件信息

评论

共有 条评论