Apple II User Manual

Page of 257
    3.  Delete all REM statements.  Each REM statement uses at least one byte plus the number
        in the comment text.  For instance, the statement 130 REM THIS IS A COMMENT uses
        24 bytes of memory.
        In the statement 140 X=X+Y: REM UPDATE SUM, the REM uses 14 bytes of memory
        including the colon before the REM.
    4.  Use variables instead of constants.  Suppose you use the constant 3.14159 ten times in
        your program.  If you insert a statement
            10 P=3.1.4159
        in the program, and use P instead of 3.14159 each time it is needed, you will save 40
        bytes.  This will also result in a speed improvement.
    5.  A program need not end with an END, so an END statement at the end of a program
        may be deleted.
    6.  Reuse variables.  If you have a variable T which is used so hold a temporary result in one
        part of the program and you need a temporary variable later in your program, use it
        again.  Or, if you are asking the terminal user to give a YES or NO answer to two differ-
        ent questions at two different times during the execution of the program, use the same
        temporary variable A$ to store the reply.
    7.  Use GOSUB's to execute sections of program statements that perform identical actions.
    8.  Use the zero elements of matrices; for instance, A(0), B(0,X).
STORAGE ALLOCATION INFORMATION
Simple (non-matrix) numeric and strong variables like V use 7 bytes; 2 for the variable name, and
5 for the value.  Simple non-matrix string variables also use 7 bytes; 2 for the variable name, 1 for
the
length, 2 for a pointer, and 2 are unused.
Matrix variables require 7 bytes to hold the header, plus additional bytes to hold each matrix element.
Each element that is an integer variable requires 2 bytes.  Elements that are string variables or
floating
point variables require 3 bytes or 5 bytes, respectively.
String variables also use one byte of string space for each character in the string.  This is true
whether the string variable is a simple string variable like A$, or an element of a string matrix
such as Q1$(5,2).
When a new function is defined by a DEF statement, 7 bytes are used to store the definition.
Reserved words such as FOR, GOTO or NOT, and the names of the intrinsic functions such as
COS, INT and STR$ take up only one byte of program storage.  All other characters in programs
use one byte of program storage each.
When a program is being executed, space is dynamically allocated on the stack as follows:
    1.  Each active FOR...NEXT loop uses 22 bytes.
    2.  Each active GOSUB (one that has not returned yet) uses 6 bytes.
    3.  Each parenthesis encountered in an expression uses 4 bytes and each temporary result
        calculated in an expression uses 12 bytes.
C  SPEED HINTS
The hints below should improve the execution time of your BASIC program.  Note that some of
these hints are the same as those used to decrease the space used by your programs.  This means
that in many cases you can increase the efficiency of both the speed and size of your programs at
the same time.
    1.  Delete all unnecessary spaces and REM's from the program.  This may cause a small
        decrease in execution time because BASIC would otherwise have to ignore or skip
        over spaces and REM statements.