A dynamic array is stored internally as a single string of characters. Whenever an element is accessed, this string has to be scanned, counting the system delimiters, to find the required data. Therefore, if the dynamic array is large, or is accessed a large number of times, a considerable amount of time is spent scanning this string. By careful programming the amount of string scanning can be minimised, resulting in an improvement in performance.
A dimensioned array stores each element as a separate variable in the descriptor table, therefore access to elements of a dimensioned array is considerably faster than to those of a dynamic array. Consider using a dimensioned array rather than a dynamic array when:
Notes:
If a dynamic array is sequentially parsed, use the REMOVE statement rather than dynamic array references to avoid repeatedly scanning the array. This can be thousands of times faster in extreme cases!
If a dynamic array only contains attribute marks, each attribute can be extracted into the variable ELEMENT by the simple construct:
LOOP REMOVE ELEMENT FROM ARRAY SETTING TERM WHILE TERM DO . . . process . . . REPEAT
When the dynamic array contains other system delimiters, each attribute can be extracted into the variable ELEMENT using the construct:
LOOP REMOVE ELEMENT FROM ARRAY SETTING TERM LOOP WHILE TERM > 2 DO DELIM=CHAR(256-TERM) REMOVE MORE FROM ARRAY SETTING TERM ELEMENT=ELEMENT:DELIM:MORE REPEAT WHILE TERM DO . . . process . . . REPEAT
The pointer can be reset back to the beginning of the dynamic array by assigning the array to itself:
ARRAY=ARRAY; *Reset REMOVE pointer
Do not access array elements repeatedly. Access once and assign to a simple variable. If accessing values and sub-values, extract the attribute to a simple variable and extract the values and sub-values from this variable.
Concatenation may be considerably faster than using <-1> references when appending to the end of a dynamic array.
Use EQUATE to define the system delimiters used in building a dynamic array:
EQU AM TO CHAR(254), VM TO CHAR(253), SVM TO CHAR(252) ... ARRAY=ARRAY:AM:VALUE1:VM:VALUE2 ...