Important Notice
The pages on this site contain documentation for very old MS-DOS software,
purely for historical purposes.
If you're looking for up-to-date documentation, particularly for programming,
you should not rely on the information found here, as it will be woefully
out of date.
Static and Dynamic Arrays
◄Variable Storage $ Memory Use► ◄Variables► ◄Contents► ◄Index► ◄Back►
──────────────────────────────────────────────────────────────────────────────
Static and Dynamic Arrays
Storage for arrays can be set aside when the program is compiled or when
the program is running:
■ Static arrays have storage set aside when the program is compiled.
■ Dynamic arrays have storage set aside when the program is run.
The storage taken by dynamic arrays can be eliminated when the
program is running in order to free memory for other uses.
How an array is declared determines whether the array is static or dynamic:
■ Arrays dimensioned with constant subscripts and implicitly
dimensioned arrays are static arrays.
■ Arrays dimensioned with variable subscripts and arrays that are first
declared in a COMMON statement are dynamic arrays.
■ In a SUB or FUNCTION not declared static, all arrays are dynamic.
■ Arrays declared using REDIM are dynamic arrays.
You can also use the $STATIC and $DYNAMIC metacommands to control how array
storage is allocated. However, the $STATIC metacommand cannot force arrays
to be static in a procedure not declared static; in such a procedure all
arrays are dynamic.
In some cases, you can allow more space for strings by replacing static
arrays with dynamic arrays or by using variable-length string arrays
stored in far memory. In compiled programs, the space for static
arrays is allocated from DGROUP, an area where strings are stored.
On the other hand, dynamic arrays and variable-length string arrays in
far memory do not take any space in DGROUP; they are stored as far objects
and require far addresses.