Data Structures and Algorithms
with Object-Oriented Design Patterns in C# |
public interface Heap { int Acquire(int size); int Release(int offset); int this[int offset] { get; set; } }The Acquire method allocates a region of size consecutive ints in the array and returns the offset of the first int in the region. The Release method release a region of ints at the specified offset which was obtained previously using Acquire. The indexer this[] provides get and set accessors to access a value in the array at a given offset.
public interface Handle { int Size { get; } int GetInt(int offset); Handle GetReference(int offset); SetInt(int offset, int value); SetReference(int offset, Handle h); }A handle refers to an object that contains either ints or other handles. The size of an object is total the number of ints and handles it contains. The various store and fetch methods are used to insert and remove items from the object to which this handle refers.
public interface Heap { Handle Acquire(int size); void Release(Handle h); void CollectGarbage(); }The Acquire method allocates a handle and space in the heap for an object of the given size. The Release method releases the given handle but does not reclaim the associated heap space. The CollectGarbage method performs the actual garbage collection operation.