Commodore 2001-8 User Manual page 143

Table of Contents

Advertisement

Appendix E
SPACE HINTS
In order to make your program smaller and save space, the following hints may be useful.
1) Use mUltiple statements per line. There is a small amount of overhead. (5 bytes) associated with each
line in the program. Two of these five bytes contain the line number of the line in binary. This means that
no matter how many digits you have In your line number (minimum line number is 0, maximum is 63999), it
takes the same number of bytes. Putting as many statements as possible in a line will cut down on the
number of bytes used by your program.
2) Delete all unnecessary spaces from your program. For instance:
10 PRINT X, Y, Z
uses three more bytes than
10 PRINTX,Y,Z
Note: All spaces between the line number and the first non-blank character are ignored.
3) Delete all REM statements. Each REM statement uses at least one byte plus the number of bytes in the
text. For instance, the statement 130 REM THIS IS A COMMENT uses up 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 1.02369 ten times in your program.
If
you insert a statement
100 = 1.02369
in the program, and use
a
instead of 1.02369 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) Re-use the same variables. If you have a variable T which is used to 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 YESor NO answer to two different 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 statemnts that perform identical actions.
8) Use the zero elements of matrices; for instance, A(O), B(O,X)
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.
t)
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.
2) THIS IS PROBABLY THE MOST IMPORTANT SPEED HINT BY A FACTOR OF 10. Use variables instead
of constants. It takes more time to convert a constant to its floating point representation than it does to
fetch the value of a simple or matrix variable. This is especially important within FOR...NEXT loops or
other code that is executed repeatedly.
E·1

Advertisement

Table of Contents
loading

This manual is also suitable for:

Pet 2001-8

Table of Contents