Classic Computer Magazine Archive COMPUTE! ISSUE 21 / FEBRUARY 1982 / PAGE 95

Odds & Ends

Clearing Memory

Charles Brannon
Editorial Assistant

Before using an area of memory for storage, it is often necessary to clear it out. For example, a GRAPHICS command clears the screen by writing zeros to all the screen memory. Since there are no BASIC statements that directly support player/missile graphics, the memory used by this facility has to be cleared by the programmer, usually with a FOR/NEXT loop.

ATARI BASIC does not clear out the old values of an array or string when a program is RUN, even if there is garbage in the memory used by these variables. This also necessitates some kind of loop to clear out this memory.

The problem with this is that an array of any substantial size requires a long time to clear out. For strings, there is a shortcut:

10 DIM A$(100)
20 A$(1) = " " : A$(100)=" " : A$(2) = A$

Line 20 will "instantly" fill A$ with spaces. The space in quotes can be changed in order to fill a string with a desired character.

There is a "quick and dirty" way to clear out memory. This relies on the previously mentioned GRAPHICS command. GRAPHICS 8 + 16 : GRAPHICS 0 will clear out about 8K of high RAM. If executed before a DIM statement, this will usually suffice. Since most Player/Missile memory is in the top of memory, the GRAPHICS command is definitely satisfactory. If you don't have 8K of free memory, you'll get an ERROR-147 (Insufficient RAM for GRAPHICS mode), in which case you'll have to use GRAPHICS 7 + 16 (or lower), or resort to the BASIC clear loop.