Heap Object Structure

Pocket Smalltalk is based on 16-bit integers. Objects in the memory-heap consist of series of 16-bit integers. 16-bit integers are used to reference both normal objects and small integers. To this purpose the least significant bit of a 16-bit reference value is encoded as follows:

The memory heap is structured as a linear list of objects, one after the other. Because of the memory management system used, this list will not become "fragmented" as objects are created and destroyed. Each object has the following layout:


Following these three header words comes the actual body of the object. For normal (pointer) objects, the body simply consists of a series of pointers, one for each named and indexed instance variable of the object (named instance variables come first). The total number of instance variables can be deduced from the length field in the object's header.

Pointerless objects are encoded slightly differently. A pointerless object consists of uninterpreted bytes, packed two per word. Since there may be an odd number of bytes, the first byte is reserved as the number of bytes to subtract from the calculated length to get the full length (in bytes) of the pointerless object. In this 16-bit (2 bytes per word) implementation, this first byte can be either 0 or 1.

Layouts of Behaviors

Instances of Behavior (i.e., classes and metaclasses) have an instance variable that specifies the "shape" of their instances. It is a small integer with the following structure:


Andrew Brault (ajb@tiac.net)