[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: DiskBrowser Software - Work In Progress



  To: Jeff Blakeney
On Sun, 21 Sep 2008 16:32:07 -0400, Jeff Blakeney wrote:

> There are reasons to put multiple statements on one line.  One reason is
> to save memory.  When you are talking about an interpreted language like
> Applesoft, every line number takes two bytes of memory and has a two
> byte pointer to the next line.  So if I write some code to initialize
> some variables and the screen like this:
> 
> 10 TEXT
> 20 HOME
> 30 D$ = CHR$(4)
> 40 F$ = "TESTFILE"
> 50 R% = 1
> 60 MR% = 100
> 
> This will take 12 bytes for the line numbers and 12 bytes for the next
> line pointers which totals 24 bytes but if I rewrite it like this:
> 
> 10 TEXT : HOME : D$ = CHR$(4) : F$ = "TESTFILE" : R% = 1 : MR% = 100
> 
> Only 2 bytes are used for the line number and only 2 bytes are used for
> the next line pointer and I've only added 5 bytes with colons for a
> total of 9 bytes which means I've just saved 15 bytes of memory.

Andy McFadden, in another thread, posted a link to the source for his
Applesoft and Integer BASIC keyword colouring routine from CiderPress
and this reminded me that I forgot about the $00 byte at the end of
every line of Applesoft.  This means that the 6 line program above
actually uses an extra 30 bytes (12 for line numbers, 12 for next line
pointers and 6 for the end of line markers) whereas the single line
version only uses an extra 10 bytes (2 for line number, 2 for next line
pointer, 1 for the end of line marker and 5 for the colons) for a total
savings of 20 bytes.

And that is just by combining six lines onto one.  Imagine the savings
by doing it as much as possible in a large program.