35.2. Lisp objects in CLISP

Three kinds of storage are distinguished:

  1. CLISP data (the heap), i.e. storage which contains CLISP objects and is managed by the garbage-collector.
  2. CLISP stack (called STACK), contains CLISP objects visible to the garbage-collector
  3. C data (including program text, data, malloced memory)

A CLISP object is one word, containing a tag (partial type information) and either immediate data or a pointer to storage. Pointers to C data have tag = machine_type = 0, pointers to CLISP stack have tag = system_type, most other pointers point to CLISP data.

Immediate objects

32-bit CPU
FIXNUM
SHORT-FLOAT
CHARACTER
64-bit CPU

In addition to the above,

SINGLE-FLOAT (with TYPECODES)

Let us turn to those CLISP objects that consume regular CLISP memory. Every CLISP object has a size which is determined when the object is allocated (using one of the allocate_*() routines). The size can be computed from the type tag and - if necessary - the length field of the object's header. The length field always contains the number of elements of the object. The number of bytes is given by the function objsize().

CLISP objects which contain exactly 2 CLISP objects (i.e. CONSes, COMPLEX numbers, RATIOs) are stored in a separate area and occupy 2 words each. All other CLISP objects have varying length (more precisely, not a fixed length) and include a word for garbage-collection purposes at their beginning.

The garbage collector is invoked every now and then by allocate_*() calls according to certain heuristics. It marks all objects which are alive (may be reached from the roots), compacts these objects and unmarks them. Non-live objects are lost; their storage is reclaimed.

2-pointer objects are compacted by a simple hole-filling algorithm: fill the left-most object into the right-most hole, and so on, until the objects are contiguous at the right and the hole is contiguous at the left.

Variable-length objects are compacted by sliding them down (their address decreases).


These notes document CLISP version 2.49Last modified: 2010-07-07