5.2 Storage allocation

5.2.1 Creating objects in Lisp

A Lisp object is a collection of consecutive memory cells. Each cell is large enough to hold the address of any Lisp object; this stored address is called a pointer. For example, a cons consists of two memory cells, one for the car and one for the cdr. A symbol consists of one memory cell for each of its components: the print name, the value, the function binding, and the property list. Some objects, such as characters or small integers, are small enough that the object itself, rather than a pointer to the object, is stored in a memory cell.

When you create a reference to a Lisp object, you normally store a pointer to that object. For example, the following expression creates a list and binds the list to a variable:

(setq newlist (list 'a 'b 'c))
The variable name is a symbol stored in the static area whose value cell points to the first element of the list. The list itself is a chain of cons cells created in the dynamic or ephemeral space whose cars point to elements of the list and whose cdrs point to successive cons cells in the list.

Lisp manipulates objects by manipulating pointers; if an object no longer has pointers to it, it becomes inaccessible. For example, the following expression changes the value of the variablenewlist:

(setq newlist (list 'd 'e 'f))
The symbol in the static area now points to a new object in dynamic space. If there are no other pointers to the list(a b c), the object that was the variable's previous value, that list is inaccessible even though it continues to take up space in memory.

Garbage collection eliminates inaccessible objects from the dynamic or ephemeral space so that there is room to create new objects. The two garbage-collecting programs in Lisp are described in Section 5.3 on page 81.


The User's Guide - 9 SEP 1996

Generated with Harlequin WebMaker