Topic : The GFA-Basic Compendium
Author : GFA Systemtechnik GmbH
Version : GFABasic.HYP v2.98 (12/31/2023)
Subject : Documentation/Programming
Nodes : 899
Index Size : 28056
HCP-Version : 3
Compiled on : Atari
@charset : atarist
@lang :
@default : Document not found
@help : Help
@options : +g -i -s +z
@width : 75
@hostname : STRNGSRV
@hostname : CAB
@hostname : HIGHWIRE
@hostname : THING
View Ref-FileIn this section we are not discussing speed optimization but the shortening of
the program. If, in a program, a string variable is assigned a
character string, as for instance a$="Test", the compiler places this character
string into the DATA segment of the program generated.
The compiler attempts to keep the initialised strings section short. When a
character string is assigned to a string variable, the compiler will first
search the already existing character string section to see if the new string
is already present there. If this is the case, it will remember the string's
address.
Example: Suppose you want to translate a program into several languages and you
therefore place all text output into a procedure in the BASIC program in order
to simplify the translation. There you will now find the lines
a$="escape key"
b$="terminate the program"
x$="the escape key will terminate the program"
During symbolic linking, the DATASTAR symbol will be inserted into the DATA
segment of the program to mark the beginning of the string section. There our
three character strings can be found one immediately after the other.
You can change the order of the three lines to
x$="the escape key will terminate the program"
a$="escape key"
b$="terminate the program"
Now you will only find the string "the escape key will terminate the program"
after DATASTAR. The reason is this: First the compiler puts the long text line
into the DATA segment. Then it is asked to initialize a string containing the
text "escape key".
To this end, it searched the DATA segment and found the text "escape key" as a
component of the long text line, noting its position in the DATA segment
without storing it again. The same happened with the text "terminate the
program".
If the long line is listed as the last one of the three, as in the first
version, the compiler will only find fragments of this line in the DATA segment
when initialising the long line. In that event, it will store the complete
string.
With a character string which is also contained in another one, the longer
string must first be assigned to a variable to enable the compiler to optimize
the use of memory space.
Strings in DATA lines are, incidentally, placed after DATASTAR before all
strings assigned to a variable. The DATA segment itself begins with a table of
local variables (VARTAB). Then follows the 48-bytes long TYPETAB, if TYPE or an
assignment using a pointer (e.g. *x=3 or SWAP *x,x%()) have been used.
After VARTAB, or TYPETAB if required, there are the INLINE areas. Only then
follows the DATASTAR symbol, behind which the contents of DATA lines and the
initialised strings can be found.