Previous section To contents Next section

17.2.4 struct array

Internally Pike uses a struct array to represent the type array. As with strings, arrays are used in many different ways, so they have many supporting functions for making them easier to manipulate. Usually you will not have to construct array structures yourself, but it is often nessecary to read data from arrays.

A struct array has these members:

INT32 refs;
The references to this array.
INT32 size;
The number of elements in the array.
INT32 malloced_size;
The number of elements there is room for in the array without re-allocating.
TYPE_FIELD type_field;
This bit field contains one bit for each type present in the array. Note that bits may be set that are not present in the array, but not vice versa. See TYPE_FIELD for more information.
INT16 flags;
ARRAY_* flags, you may set one or more of:
struct svalue item[size];
This is a variable-size array of svalues which contains the actual values in this array.
Here is an example function which will print the type of each value in an array:
void prtypes(struct array *a)
{
    INT e;
    for(e=0;e<a->size;e++)
        printf("Element %d is of type %d\n",e,a->item[e].type);
}

FUNCTION
allocate_array

FUNCTION
free_array

FUNCTION
array_index

FUNCTION
array_index_no_free

FUNCTION
simple_array_index_no_free

FUNCTION
array_set_index

FUNCTION
push_array_items

FUNCTION
aggregate_array

FUNCTION
f_aggregate_array

FUNCTION
append_array

FUNCTION
explode

FUNCTION
slice_array

FUNCTION
add_arrays

FUNCTION
copy_array

Previous section To contents Next section