Options for handling arrays:
There are three types of arrays:
For static arrays there are the functions:
Name |
Purpose |
Arguments |
Return value |
Example |
high |
yields the index of the last array element if array is multi dimensional, the first index is used |
1: array |
INTEGER |
i:=high (array);
|
length |
yields the length of the array |
1: array |
INTEGER |
but length(a[1])==length(b[1])==4 |
low |
yields the index of the first array element |
1: array |
INTEGER |
i:=low (array); |
For dynamic arrays there are the functions:
Name |
Purpose |
Arguments |
Return value |
Example |
append |
appends an array or an array element to another array
|
1: array of: Dest=dyn. array |
None |
|
capacity |
yields the maximal number of elements that a dynamic array can obtain without automatic memory allocation (does not necessary match the array length) |
1: array: Source |
INTEGER |
i:=capacity(arObjects); |
copy |
copies an array onto another one |
1: array: Source |
array of: Dest |
|
high |
yields the index of the last array element |
1: array of |
INTEGER |
i:=high (arObjects); |
insert |
inserts an array or an array element into another array at a certain position |
1: array of: Dest=dyn. array |
None |
|
length |
yields the length of the array |
1: array of |
INTEGER |
|
low |
yields the index of the first array element |
1: array of |
INTEGER |
i:=low (arObjects); |
remove |
removes certain elements from an array |
1: array of: dyn. array |
None |
|
reserve |
allocates the storage space for a certain number of elements in an array (no elements are created or deleted, only the necessary storage is reserved) |
1: array of: dyn. array |
None |
reserve(arObjects,100); |
setLength |
sets the length of the array to a new value |
1: array of: dyn. array |
None |
var dyn_arr: array of real; |
reserve |
Release 11 allows minimum memory reservation for a given number of elements in an array (Please note: no elements are created or deleted, but only the required memory is reserved) reserve does NOT replace the call to setLength) - this function can be used for long-term Optimization can be used to unnecessary Avoid reallocations of the array memory |
1: dyn. array 2: INTEGER: Number of items to reserve |
|
var arr: array of string; i: integer; begin reserve( arr, 2000000); println(capacity(arr)); for i:=0 to 1999999 do begin println("finished"); end.
|
capacity |
Release 11 returns the maximum number of elements the array can contain without automatically creating new memory |
1: dyn. array |
|
See reserve |
For open arrays there are the following functions:
Name |
Purpose |
Arguments |
Return value |
Example |
setLow |
Sets the index of the first element |
1: array * of |
array * of |
procedure PrintCA (a: array * of char); var dyn_c: array of char; PrintCA (dyn_c); |
sliceLeft |
yields the n first elements of an array |
1: array |
array * of |
|
sliceMid |
yields the n elements of an array from a certain position onwards |
1: array |
array * of |
|
sliceRight |
yields the n last elements of an array |
1: array |
array * of |