General Category > Programming

BASIC array memory

(1/2) > >>

ivavilagu:

--- Code: ---10 dim a(100)
20 print @a(0)
30 m=2
40 print @a(0)
50 s=4
60 print @a(0)
70 n=8
80 print @a(0)
90 print @a(0)
100 print @a(0)
--- End code ---


Result:
497
506
515
524
524
524


Why memory direction of array changes every new variable declaration?

Sykobee (Briggsy):
It sounds like the memory allocation for new variables results in existing variables being moved around. There is probably something that explains the runtime allocation of variables somewhere but I can't find it at the moment.


That might be why a lot of basic programs predefine all the variables up front, as memory copying isn't cheap.


BASIC itself starts at &170, and when the program runs the variables seem to be placed just after the end of the basic program. As you add to the basic program, the variables get higher addresses.


DIM a%(128):poke @a%(0)+offset,value:b$=peek(@a%(0)+offset) - I think this lets you access a byte[] of size 256 in BASIC which doesn't have this natively - useful if you are running out of memory for, e.g., screen maps, etc.

ivavilagu:
Ok, but only moves memory with arrays.


It seems is better to declare all variables at beginning.

abalore:
You are not checking the address of the array, but the address of the first element

eto:

--- Quote from: abalore on 15:22, 18 November 21 ---You are not checking the address of the array, but the address of the first element

--- End quote ---


the address of the first element of the array is equal to the address of the array.

Navigation

[0] Message Index

[#] Next page

Go to full version
Powered by SMFPacks Reactions Mod
Powered by SMFPacks Alerts Pro Mod
Powered by SMFPacks Mentions Pro Mod