Array Implementation

Describes the features of arrays and the ways in which they are implemented.

All arrays have an array buffer allocated from the heap. The implementation of this buffer and the way it is used depends on the specific type of array.

In arrays of elements which all have the same length, the elements are contained within the array buffer itself.

In arrays of elements with varying length, each element is contained within its own heap cell and the array buffer contains pointers to the elements.

In packed arrays, the elements are contained within the array buffer. A packed array is an array of elements of varying length where the length information for an element precedes that element within the array buffer.

Logically, an array buffer is linear but, physically, it can be organised either as a flat buffer or a segmented buffer.

In general, you can choose between array classes which use a flat buffer and array classes which use a segmented buffer. The choice depends on how the array is to be used.

A segmented array buffer is implemented using a CBufSeg object.

A flat array buffer is implemented either:

  • directly by the array as a piece of linear memory.

or

  • using a CBufFlat object.

The first type is a simple and efficient implementation but has some restrictions on the size of an array element and is limited to holding elements which have the same length. The second is a more general implementation and is only limited by the available memory.