Question: 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

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 little heap , or a lot of heap space and a little stack, as it chooses. Implement a MemoryManager class that combines the features of the StackManager

Exercise 3 Older language systems often managed one heap and one stack

and the HeapManager classes

together in the same big block of memory. Embedded systems are sometimes

still implemented this way. The heap lives at the low end of

Like them, it should have a constructor that takes as a parameter the memory array to be managed:

the block and the stack at the high end. The memory manager

The implementation should start with an empty stack and an empty heap. The heap should grow upwards only as necessary to satisfy allocation requests. Make sure to handle both ways of running out of memory cleanly. Don't let the stack run into the heap of the heap run into the stack. (when the push method finds that it is going to run into the heap, it could check whether the last block in the heap is free and, if so, remove it from the heap and use that space for the stack. But you do not have to implement this refinement. Your heap needs to be able to grow up toward the stack, but need never shrink.)

public class StackManager private in memory; the memory we manage private in top; index of top (lowest) stack block t Stack Manager constructor. param initial Memory the in of memory to manage t[ public stackManager (int initial Memory) memory nitial Memory top memory. length; Allocate a block and return its address. aparam requestsize int size of block, 0 Ereturn block address throws StackOverflowError if ou of stack space public int push(int requestsize) int oldtop top top (requestsize 1); extra word for oldtop if (top 0) throw new StackOverflowError memory [top] oldtop return top 1; Pop the top stack frame. This works only if the stack is not empty public void pop() top memory [top]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Implementation of MemoryManager Class The MemoryManager class combines both StackManager and HeapMan... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!