array

Syntax

array(dataType|template, [initialSize], [capacity], [defaultValue])

Arguments

dataType is the data type for the vector.

template is an existing vector. The existing vector serves as a template and its data type determines the new vector’s data type.

initialSize is the initial size (in terms of the number of elements) of the vector.

capacity is is the amount of memory (in terms of the number of elements) allocated to the array. When the number of elements exceeds capacity, the system will first allocate memory of 1.2~2 times of capacity, copy the data to the new memory space, and release the original memory.

defaultValue is the default value of the vector. It must be a scalar. If defaultValue is not specified, it defaults to NULL for strings and symbols and 0 for other data types.

Details

Return a vector.

Examples

$ x=array(int, 10, 100, 1)
// initial size is 10; capacity is 100; default value is 1
$ x
[1,1,1,1,1,1,1,1,1,1]

$ x=array(int, 0)
// initialize an empty vector
$x
[]
$ x.append!(1..10)
[1,2,3,4,5,6,7,8,9,10]

$ y=array(x)
$ y
[0,0,0,0,0,0,0,0,0,0]

$ syms=array(symbol, 0, 100)
// an empty symbol vector with capacity of 100

$ typestr syms
FAST SYMBOL VECTOR