|
ADS
Algorithms and Data Structures
|
A heap of cells of two fields with a garbage collector, beyond the book: the memory of a LISP, where a field holds nil, an atom or the address of a cell, and the cells not reachable from the roots are garbage. More...
#include "ADS/Contract.h"#include <cstddef>#include <set>#include <vector>#include "ADS/memory/impl/CellHeap.tpp"Go to the source code of this file.
Classes | |
| class | ADS::CellHeap |
| a heap of cells of two fields, with a mark-and-sweep collector More... | |
Namespaces | |
| namespace | ADS |
A heap of cells of two fields with a garbage collector, beyond the book: the memory of a LISP, where a field holds nil, an atom or the address of a cell, and the cells not reachable from the roots are garbage.
collect() marks the reachable cells and sweeps the others onto the free list, and cons() collects when the free list is empty. The marking is that of Deutsch, Schorr and Waite (Algorithm 2.3.5E of TAOCP): the depth-first visit keeps its path in the fields of the cells themselves, reversing each pointer it follows and restoring it on the way back, with one bit per cell telling which field holds the reversed pointer; it needs no stack, which a collector cannot count on when the memory is exhausted, and takes time linear in the cells reached. A recursive marking with a stack is kept for the comparison. The sweep reads every cell, so that a collection costs \( O( n ) \) time on a heap of \( n \) cells, whatever the cells reached.
The contracts [see Contract.h]: an address is a cell of the heap, and the cell read, written or made a root is not free; cons() needs a free cell after a collection; collect() ensures that it frees exactly the cells that are not reachable and leaves the fields of the others as they were, an audit. The operations are defined in CellHeap.tpp.