Other tips – Remote Processing CAMBASIC User Manual

Page 25

Advertising
background image

Program ing Tips - 2

can use PC Sm artLINK to strip out the remar ks in the final program. H owever, this may have a significant
impact on clarity. Do this only if a ll other m ethods fail.

10.

Spaces have no affect on spee d since they are elimina ted in the compiling proce ss.

11.

Data statements execute slowly. If you need large data tables, load them into RAM at the start of the
program, and access them with the PEEK function. While this is less convenient, it is faster.

12.

The PRIN T USIN G statement takes longer to execute than PRINT, as it must format before sending the
character s.

13.

FPO KE and FP EEK are the fastest memory accesses. T hey move four bytes at a time. If you have enough
memory to store multiple bytes, then use these constructs rather than PEEK, POKE, DPEEK and DPOKE.

FPOKE A%,B%

is more than twice as fast as

POKE A,B

in an average program

14.

Array handling is, by its nature, slow in any language. Avoid multi-dimension arrays when possible.

15.

When possible, use the DO/ENDDO loop instead of the FOR/NEXT. It is much faster.

16.

The m ost effective w ay to speed up a progr am is thr ough good p rogr amm ing. Highly m odular pr ogram s with
lots of subroutines and GOSUBs are easy to develop, read and maintain. However, they are slower than
optimizing program flow for speed.

17.

When using a FOR /NE XT loop, avoid placing the variable after NEXT. This forces CAM BASIC to verify
the variable name and slow down execution of the loop.

10 NEXT

fast

10 NEXT D

slow

18.

Do not use exponent to square or cube a number. It is a very slow operation.

10 A=X$2

very slow

10 A=X*X

fast

10 A=X*X*X

better than x

$

3

Other Tips

1.

Sometimes a system will crash without any obvious cause. The cr ashing can occur because part of the
memory used by CAM BASIC has been modified by a POKE statement that is out of bounds. For example,

10 POKE A,B

The variable A is the address at which the POKE occur s. If the value of A inadvertently falls into the wrong
area, unpredictable results may occur. Some of these are:

a.

Error message for a nonexistent line number.

Advertising