< Back

Lecture 15 - Memory and Garbage Collection


Esoteric "Today"


Activity

Write a class called Heap, which has 1 field: words. This field should be an array of integers. The size of this array should be specified to the constructor for Heap.

In addition, this class should have 2 methods: allocate and deallocate. Allocate takes an integer as a parameter, and returns an integer which is a "pointer" to the location in memory allocated for that size. Deallocate takes a "pointer" and returns that memory location to the heap.

The structure of the heap should be as follows: