GOLF(2gg)

NAME
new-array - (array)

PURPOSE
Create array.

SYNTAX

        new-array <array> [ max-size <max-size> ] [ process-scope ]  [ type string | number | bool ]

DESCRIPTION
new-array creates new <array>. An array is an indexed array, with a number as an index, and with a either a string, number or boolean as an element in the array. By default (without "type" clause), <array> is an array of strings. You can specify "string", "number" or "bool" in "type" clause, in which case <array> is an array of strings, numbers or booleans respectively.

An array is flexible, which means that it will grow as needed. By default, an array allocates room for 256 elements that can grow up to 1,000,000 elements, unless <max-size> number (in "max-size" clause) is specified in which case it can grow up to <max-size> elements. <max-size> must be at least 256.

Note that max-size specifies only the upper limit of allocation. The actual amount of memory allocated can vary.

You do not need to pre-size the array; rather when you write an element, it will resize automatically. For instance, you can set an array element arr[0] and then arr[1000] (with nothing in-between), the array will be automatically extended to accommodate. Note that it will not automatically contract when tailing elements are deleted. Use purge-array to delete all elements in the array and shrink its memory footprint when your processing is done.

SCOPE

Note that an array is accessible to the current request only, unless "process-scope" clause is used, in which case all requests served by a process can use it (see do-once for a typical way to do this).

If "process-scope" is used, then <array> will keep its data across all requests in a given process. See write-array for an example of a process-scoped array.

EXAMPLES
Create a new array:

        new-array arr

SEE ALSO
 Array

new-array purge-array read-array write-array See all documentation