CS 401 Memory Manager 50 Points This program will be a memory manager. You will need to complete the following tasks using thejava code given on Canvas. Tasks: Allocate memory if memory is available...



CS 401


Memory Manager


50 Points


This program will be a memory manager. You will need to complete the following tasks using thejava code

Preview the document
given on Canvas.


Tasks:



  1. Allocate memory if memory is available (exclusive).

  2. Keep track of free and used blocks.

  3. Pass the automated jUnit tests.

  4. Compact memory when given back.

  5. Do all tasks in a concurrent fashion.

    1. Do not change the method signatures for the code.

    2. Back sure that your data is not corrupted.




Turn in:
A file named MemoryManager.java




Screen Shot 2020-10-21 at 10.47.30 PM.png


Note: Case 2 will run forever requesting and releasing memory until you terminate the program.



Screen Shot 2020-10-21 at 10.49.13 PM.png




import java.util.TreeMap; public class MemoryManager { TreeMap free; // Here, the key is the value where the memory starts and the value is the area of the memory which contains the beginning, end, and size of the memory TreeMap used; public MemoryManager(int size) { free = new TreeMap(); used = new TreeMap(); free.put(0, new Area(0, size)); } public Area aquire(int amount) { synchronized (free) { // go through every entry in free // check if the block of free memory is large enough for the amount requested // if the block is large enough, add the requested block to the used memory TreeMap // since you added memory to the used block, you need to remove the same amount of memory from the free block // return the area object from the for loop // check if the start of the free block is the same as the end of the free block // then, remove the block from the free TreeMap // return null from this if statement } return null; } public void release(int startAddress) { synchronized (free) { // if the start address is a key in the used TreeMap // release the block from the used TreeMap and add this block back to the fre TreeMap // Here, you will need to combine free memory whenever possible } } public void print() { synchronized (free) { System.out.println("\nFree"); free.forEach((k, v) -> System.out.println(k + "->" + v.getEnd() + "(" + v.getSize() + ")")); System.out.println("Used"); used.forEach((k, v) -> System.out.println(k + "->" + v.getEnd() + "(" + v.getSize() + ")")); } } public Area getFirstFree() { return free.firstEntry().getValue(); } } import java.util.TreeMap; public class MemoryManager { TreeMap free; // Here, the key is the value where the memory starts and the value is the area of the memory which contains the beginning, end, and size of the memory TreeMap used; public MemoryManager(int size) { free = new TreeMap(); used = new TreeMap(); free.put(0, new Area(0, size)); } public Area aquire(int amount) { synchronized (free) { // go through every entry in free // check if the block of free memory is large enough for the amount requested // if the block is large enough, add the requested block to the used memory TreeMap // since you added memory to the used block, you need to remove the same amount of memory from the free block // return the area object from the for loop // check if the start of the free block is the same as the end of the free block // then, remove the block from the free TreeMap // return null from this if statement } return null; } public void release(int startAddress) { synchronized (free) { // if the start address is a key in the used TreeMap // release the block from the used TreeMap and add this block back to the fre TreeMap // Here, you will need to combine free memory whenever possible } } public void print() { synchronized (free) { System.out.println("\nFree"); free.forEach((k, v) -> System.out.println(k + "->" + v.getEnd() + "(" + v.getSize() + ")")); System.out.println("Used"); used.forEach((k, v) -> System.out.println(k + "->" + v.getEnd() + "(" + v.getSize() + ")")); } } public Area getFirstFree() { return free.firstEntry().getValue(); } } Microsoft Word - Document1 CS 401 Memory Manager 50 Points This program will be a memory manager. You will need to complete the following tasks using the java code given on Canvas. Tasks: 1. Allocate memory if memory is available (exclusive). 2. Keep track of free and used blocks. 3. Pass the automated jUnit tests. 4. Compact memory when given back. 5. Do all tasks in a concurrent fashion. 1. Do not change the method signatures for the code. 2. Back sure that your data is not corrupted. Turn in: A file named MemoryManager.java Note: Case 2 will run forever requesting and releasing memory until you terminate the program. Microsoft Word - Document3 import java.util.TreeMap; public class MemoryManager { TreeMap free; // Here, the key is the value where the memory starts and the value is the area of the memory which contains the beginning, end, and size of the memory TreeMap used; public MemoryManager(int size) { free = new TreeMap(); used = new TreeMap(); free.put(0, new Area(0, size)); } public Area aquire(int amount) { synchronized (free) { // go through every entry in free // check if the block of free memory is large enough for the amount requested // if the block is large enough, add the requested block to the used memory TreeMap // since you added memory to the used block, you need to remove the same amount of memory from the free block // return the area object from the for loop // check if the start of the free block is the same as the end of the free block // then, remove the block from the free TreeMap // return null from this if statement } return null; } public void release(int startAddress) { synchronized (free) { // if the start address is a key in the used TreeMap // release the block from the used TreeMap and add this block back to the fre TreeMap // Here, you will need to combine free memory whenever possible } } public void print() { synchronized (free) { System.out.println("\nFree"); free.forEach((k, v) -> System.out.println(k + "->" + v.getEnd() + "(" + v.getSize() + ")")); System.out.println("Used"); used.forEach((k, v) -> System.out.println(k + "->" + v.getEnd() + "(" + v.getSize() + ")")); } } public Area getFirstFree() { return free.firstEntry().getValue(); } } import java.util.TreeMap; public class MemoryManager { TreeMap free; // Here, the key is the value where the memory starts and the value is the area of the memory which contains the beginning, end, and size of the memory TreeMap used; public MemoryManager(int size) { free = new TreeMap(); used = new TreeMap(); free.put(0, new Area(0, size)); } public Area aquire(int amount) { synchronized (free) { // go through every entry in free // check if the block of free memory is large enough for the amount requested // if the block is large enough, add the requested block to the used memory TreeMap // since you added memory to the used block, you need to remove the same amount of memory from the free block // return the area object from the for loop // check if the start of the free block is the same as the end of the free block // then, remove the block from the free TreeMap // return null from this if statement } return null; } public void release(int startAddress) { synchronized (free) { // if the start address is a key in the used TreeMap // release the block from the used TreeMap and add this block back to the fre TreeMap // Here, you will need to combine free memory whenever possible } } public void print() { synchronized (free) { System.out.println("\nFree"); free.forEach((k, v) -> System.out.println(k + "->" + v.getEnd() + "(" + v.getSize() + ")")); System.out.println("Used"); used.forEach((k, v) -> System.out.println(k + "->" + v.getEnd() + "(" + v.getSize() + ")")); } } public Area getFirstFree() { return free.firstEntry().getValue(); } }
Oct 27, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here