When dimensioning a string array (e.g., DIM AB$(1,2,3)), the Commodore BASIC memory allocates a header in the variable area.
Header Structure:
- Character 1: The first character of the field name (displayed inverted to indicate it is a string field).
- Character 2: The second character of the field name.
- Characters 3 & 4: The address where the string data is stored, represented as a Low-Byte and High-Byte pair.
- Characters 5 & 6: The length of the string (in bytes).
Data Storage:
Each element in the array occupies a specific number of bytes. For an array like AB$(1,2,3), the total elements are $2 imes 3 imes 4 = 24$. If the header uses 11 bytes, the remaining space is divided by the number of elements to find the size per element.
Each element's data block contains:
- Byte 1: The length of the string.
- Bytes 2 & 3: The Low-Byte and High-Byte of the address where the actual string characters are stored in the fourth memory block.
DIM AB$(1,2,3)
AB$(0,0,0) = "AAAAAA"
AB$(1,2,3) = "BB"