Question: StackManager.java public class StackManager { private int[] memory; // the memory we manage private int top; // index of top (lowest) stack block /** *
![StackManager.java public class StackManager { private int[] memory; // the memory](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f3d231253f9_08866f3d2305462e.jpg)

StackManager.java
public class StackManager { private int[] memory; // the memory we manage private int top; // index of top (lowest) stack block /** * StackManager constructor. * @param initialMemory the int[] of memory to manage */ public StackManager(int[] initialMemory) { memory = initialMemory; top = memory.length; } /** * Allocate a block and return its address. * @param requestSize int size of block, > 0 * @return block address * @throws StackOverflowError if out of stack space */ public int push(int requestSize) { int oldtop = top; top -= (requestSize + 1); // extra word for oldtop if (top
HeapManager.java
public class HeapManager { static private final int NULL = -1; // our null link public int[] memory; // the memory we manage private int freeStart; // start of the free list /** * HeapManager constructor. * @param initialMemory the int[] of memory to manage */ public HeapManager(int[] initialMemory) { memory = initialMemory; memory[0] = memory.length; // one big free block memory[1] = NULL; // free list ends with it freeStart = 0; // free list starts with it } /** * Allocate a block and return its address. * @param requestSize int size of block, > 0 * @return block address * @throws OutOfMemoryError if no block big enough */ public int allocate(int requestSize) { int size = requestSize + 1; // size including header // Do first-fit search: linear search of the free // list for the first block of sufficient size. int p = freeStart; // head of free list int lag = NULL; while (p != NULL && memory[p] 1) { // if more than a header's worth nextFree = p + size; // index of the unused piece memory[nextFree] = unused; // fill in size memory[nextFree+1] = memory[p+1]; // fill in link memory[p] = size; // reduce p's size accordingly } // Link out the block we are allocating and done. if (lag == NULL) freeStart = nextFree; else memory[lag + 1] = nextFree; return p+1; // index of useable word (after header) } /** * Deallocate an allocated block. This works only if * the block address is one that was returned by * allocate and has not yet been deallocated. * @param address int address of the block */ public void deallocate(int address) { int addr = address - 1; memory[addr + 1] = freeStart; freeStart = addr; } }// end of HeapManager.java Exercise 3 older language systems often managed one heap and one stack together in the same big block of memory. Embedded systems are sometimes still implemented this way. The heap lives at the low end of the block and the stack at the high end. The memory manager prevents them from running into each other but does not use a fixed partition. A program can use a lot of stack space and a litt heap, or a lot of heap space and a little stack, as it chooses. Implement a MemoryManager class that combines the features of the stack Manager and the HeapManager classes from this chapter. The code for stackManager and HeapManager is available on this book's Web site.) Like them, it should have a constructor that takes as a parameter the memory array to be managed public Memory Manager (int initialMemory) Like stackManager it should have methods to push and pop stack blocks: public int push (int requestsize) public void pop Like it have methods to allocate and deallocate hea HeapManager should blocks: public int allocate (int requestsize). public void deal locate (int address) Exercise 3 older language systems often managed one heap and one stack together in the same big block of memory. Embedded systems are sometimes still implemented this way. The heap lives at the low end of the block and the stack at the high end. The memory manager prevents them from running into each other but does not use a fixed partition. A program can use a lot of stack space and a litt heap, or a lot of heap space and a little stack, as it chooses. Implement a MemoryManager class that combines the features of the stack Manager and the HeapManager classes from this chapter. The code for stackManager and HeapManager is available on this book's Web site.) Like them, it should have a constructor that takes as a parameter the memory array to be managed public Memory Manager (int initialMemory) Like stackManager it should have methods to push and pop stack blocks: public int push (int requestsize) public void pop Like it have methods to allocate and deallocate hea HeapManager should blocks: public int allocate (int requestsize). public void deal locate (int address) Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
