联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-23:00
  • 微信:codehelp

您当前位置:首页 >> OS程序OS程序

日期:2023-12-13 08:02

Assignment 2: Memory Allocation
In this assignment, you need to simulate contiguous memory allocation using first fit, best fit,
and worst fit strategies. Refer to Chapter 9.2.2 for more information about them.
Problem statement:
In this assignment, you need to implement a simulation mechanism that performs allocations,
deallocations, and compact operations on a memory layout. The simulation will try to allocate
blocks starting from the lowest addresses of memory (i.e., from 0) to the highest ones. Each block
will have an integer ID. You can use any data structure you see fit to represent and handle your
memory, as long as your code imports elements from the java library only. Remember that each
address has a unary capacity, so a block with a dimension of 5 will be positioned, starting from
the lowest address, from 0 to 4.
The classes for the three instruction types are provided, and they all extend from an empty base
abstract class, Instruction:
? AllocationInstruction is specified with the block ID to allocate and with the
dimension of such block.
? DeallocationInstruction is specified with the block ID to deallocate.
? CompactInstruction takes no additional parameters and should compact the
content of the memory towards the lowest addresses, without altering the order of blocks
in memory. The image exemplifies this instruction’s expected behavior.
You should also handle all the occurrences in which an AllocationInstruction or a
DeallocationInstruction can fail, adding a new InstructionException inside
your SimulationInstanceImpl class and continuing the execution, if needed.
Allocations can fail when the memory has no space for the new block or the same block ID
already exists in memory. Deallocations can fail when trying to deallocate blocks that are not in
the memory. When any InstructionException is generated, you should also pass as an
argument the maximum possible allocatable memory at that moment, i.e., the size of the
biggest free slot in the memory at that instant. Note that this value, most of the time, is not
equal to the total free memory.
To calculate your memory fragmentation, refer to the following formula:
IMPORTANT: remember that, if you are adopting BEST_FIT or WORST_FIT and you have more than
one eligible hole for an AllocationInstruction, you should choose the one with the
lowest address among them. For FIRST_FIT, always start from the address 0 when searching for a
valid hole.
Your goal for this assignment is to fill out the methods in the required classes MemoryImpl and
SimulationInstanceImpl without altering the content of the provided package or the
provided sample tests. The details on what is expected from those methods are contained in the
TODO blocks inside them.
BE SURE TO READ THEM CAREFULLY BEFORE STARTING WITH YOUR CODE IMPLEMENTATION!
One of the tests is comprehensive (twoInstructionsTest) and should give you a better
understanding of each method’s expected behavior.
Write all the new classes that you need for this assignment inside the
se.lnu.os.ht23.a2.required package. That means:
1. Any code that you write out of that package will be ignored when evaluating the
assignment. If you write code out of that package, comments like “it worked on my
computer” will arise, and you will be gently directed to these two points.
2. Do not move any of the existing classes/interfaces that we have provided in the
provided package to the required package because it will create duplicates when
we evaluate the code, compilation problems, “it worked on my computer” situations, etc.,
and you will be gently directed to these two points.
Only one member of the group must submit the solution to Moodle. Check the names.txt file
and replace the contents with the actual student ID of the participants. One student ID per line.
The line must contain only the student ID. This is automatically read.
Summary:
Write the necessary code to make methods in classes MemoryImpl.java and
SimulationInstanceImpl.java work as described in their TODOs and this
document. Fill the names.txt file with your actual IDs.
Do not change the provided interfaces or the test class!
Other considerations:
We will execute your solution under different test conditions. We have provided the most
straightforward tests. Only submit your solution if it passes the provided test class
SimulationTests.java.
Part B (for an Excellent):
Fill out the overridden method equals in the MemoryImpl class (please note that it MUST
take a parameter of the generic class Object for it to be a proper override). This is the method
that is used by AssertEquals and should return true only when two Memories are structured
exactly in the same way (same dimension, blocks, and disposition), regardless of the Simulation
they come from.

相关文章

版权所有:留学生编程辅导网 2021,All Rights Reserved 联系方式:QQ:99515681 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。