Memory Management

All Treescript data in memory is stored in 256-byte pages. There are 2 kinds of pages: list node pages and array pages. List node pages consist of 25 list nodes, while array pages consist of one list node followed by 240 bytes of array data. Each element of this array is either 1 byte or 2 bytes long. List nodes are 10 bytes long, and consist of a 16-bit header and two 32-bit pointers. The first pointer is referred to as the pchild pointer, and the second pointer is referred to as the pnext pointer.

 

Data Structures

·      Linked List: used for operator stack, operand stack, expressions, arrays of 4- or 8-byte values, lists of array pages, and the free-node list.

·      Tree: similar to a linked list, except that each element of the list can itself be a list, to an arbitrary depth. Used for program code, multi-dimensional arrays, and large one-dimensional arrays.

·      Array Pages: used for arrays of 1- or 2-byte values. If array is larger than 240 bytes, a linked list of array pages is used to represent the array.

·      Dynamic Arrays: all arrays are dynamic, meaning that they can grow or shrink at run-time.

·      Sets: stored in array pages; maximum length = 240 x 8 = 1920 bits (no. of elements).

·      Atomic Values: the values of primitive data types are stored in list nodes, replacing the left pointer (except for 8-byte values, which replace both the left and right pointers).

 

Garbage Collection

The linked list of pages containing list nodes is sorted by no. of free nodes, so that list node allocation occurs in pages having the fewest free nodes.

 

Garbage collection is automatic, freeing the programmer from having to worry about freeing up memory used by data which is no longer needed.