intel MCS BASIC-52 — Intel MCS BASIC-52 Versions 1 & 1.1 Operating and Reference Manual PDF (EN)

int e l 4.31 DESCRIPTION OF STATEMENTS STATEMENT: STRING [expr], [expr] MODE: COMMAND and/or RUN TYPE: CONTROL The STRING [expr],[expr] statement allocates memory for strings. Initially, no memory is allocated for strings. If the user attempts to define a string with a statement such as LET $(1)="HELLO" before memory has been allocated for strings, a MEMORY ALLOCATION ERROR will be generated. The first expression in the STRING [expr],[expr] statement is the total number of bytes the user wishes to allocate for string storage. The second expression denotes the maximum number of bytes that are in each string. These two numbers determine the total number of defined string variables.

You might think that the total number of defined strings would be equal to the first expression in the STRING [expr],[expr] statement divided by the second expression. Ha,ha, do not be so presumptuous. MCS BASIC-52 requires one additional byte for each string, plus one additional byte overall. This means that the statement STRING 100,10 would allocate enough memory for 9 string variables, ranging from $(0) to $(8) and all of the 100 allocated bytes would be used. Note that $(0) is a valid string in MCS BASIC-52. After memory is allocated for string storage, neither commands, such as NEW nor statements, such as CLEAR, will "de-allocate" this memory.

The only way memory can be de-allocated is to execute a STRING 0,0 statement. STRING 0,0 will allocate no memory to string variables. IMPORTANT NOTE Every time the STRING [expr],[expr] statement is executed, MCS BASIC-52 executes the equivalent of a CLEAR statement. This is a necessity because string variables and numeric variables occupy the same external memory space. So, after the STRING statement is executed, all variables are "wiped-out." Because of this, string memory allocation should be performed early in a program (like the first statement or so) and string memory should never be "re-allocated" unless the programmer is willing to destroy all defined variables. - 66 -