-
Notifications
You must be signed in to change notification settings - Fork 1
heap.dasm16
The heap is essentially a linked list of regions. Each region consists of a two-word header (see below) followed by the allocated memory.
The header consists of a size for the region (not including the header) and a pointer to the header of the next region (0 for last region). The high bit of the size word is actually a flag, with 1 meaning the region is free, and 0 meaning it's in use.
(location, length)
Sets env.heap to the location of the first heap region's header, as given in location. The given length is the total length of the heap, including the header.
The heap is not zeroed; the contents of newly allocated memory are arbitrary and undefined.
Reserves a consecutive block of length words of memory in the heap.
Currently a bit dim; uses the first sufficiently large region, not necessarily the best one. This trades increased memory fragmentation for speed.
returns the location of the reserved memory, or 0 if no block of the requested size could be found.
modifies A
Marks the region starting at location as free. MUST BE THE BEGINNING OF THE .alloc'd REGION. Collapses adjacent free blocks into one.
Conducts sanity checking on the heap. Checks for three failure modes (given here in the order they are run, which is also descending importance):
- Regions do not overlap, nor are there gaps.
- No free regions are adjacent.
Returns 0 if things are sane, or the number of the problem encountered otherwise.