Date : Sat, 30 Oct 2004 16:58:51 +0100
From : Jeremy C B Nicoll <Jeremy@...>
Subject: Re: Dimensioned area space
In article <Marcel-1.53-1030153748-0b0zokP@...>,
Andrew W <a.weston2@...> wrote:
> If in BASIC I type:
> DIM A%-1
> P.A%-TOP
> I get as expected: '0'
> If I type
> DIM A%-1
> P.A%-TOP
> DIM G% 0
> P.A%-TOP
> I get '1' as expected (I think I expected it anyway ;-))
> However if I type:
> DIM A%-1
> P.A%-TOP
> DIM GH% 0
> P.A%-TOP
> I get '10'
> where is the memory going?
If the BASIC in BBCs is like that in later machines, the integer
variables A% B% ... Z% are special, in that space is permanently
reserved for them (so using those variables is fast in programs because
the BASIC interpreter will always find the values in the same fixed
place).
Other variables though - eg "GH%" - are stored in whatever memory is
free for their use at the time, and what's more the name "GH" or
possibly even "GH%" has to be stored along with some pointer to where
the value will be. That's so that when your program later refers to
"GH%" the interpreter can scan its list of known variables and find the
instance that is GH% and thus the value. The difference in storage
you're seeing is probably the amount of space taken up by the
variable's name in th list of all user-defined variables. (Or list of
all user-defined integer variables, or list ... with names starting
"G").
--
Jeremy C B Nicoll - my opinions are my own.