Question about arrays and byte consumption

By JohnHassink

Ambassador (5655)

JohnHassink의 아바타

22-02-2011, 17:25

Hello.
I made an (NBASIC) program which uses quite a few arrays.
In the first version, I dimensionalise them from 0 to 4, which are all used by player plus 4 enemies.
With ?FRE(0) it shows 17807 bytes free.

Then, I dimensionalise them from 0 to 3, so one enemy less (and less VDP 'action' too, ofcourse).
Now, instead of that making free some more memory, I'm left with 17796 bytes. Question

Is this purely the 'fine' for using uneven instead of even numbers?

Login or 등록 to post comments

By flyguille

Prophet (3031)

flyguille의 아바타

22-02-2011, 17:35

0 to 3 means = 4 elements in the array.

10 dim a%(10)

means 11 elements.

By JohnHassink

Ambassador (5655)

JohnHassink의 아바타

22-02-2011, 17:38

Sorry, I do not understand.
What I used is just like DIM A(4).

What is the function of using DIM A% ?

By Vampier

Prophet (2409)

Vampier의 아바타

22-02-2011, 17:57

a% forces the value to be a integer (not floating points)

By JohnHassink

Ambassador (5655)

JohnHassink의 아바타

22-02-2011, 18:10

Thanks, both!
Final question: is using % not necessary when everything from A-Z is declared integer with DEFINT anyway?

Final question 2: Smile so, the byte loss is due to dimensionalising with uneven instead of even numbers?

By flyguille

Prophet (3031)

flyguille의 아바타

22-02-2011, 18:24

when you uses DEFINT A-Z all will go INTEGER unless explicit declaration like A!=0 (floating point) B$="" (string).

Anyway, rember that in the array , the element number zero also counts.... it is not just 1,2,3,4 it is 0,1,2,3,4 (five elements)

By flyguille

Prophet (3031)

flyguille의 아바타

22-02-2011, 18:25

and NO, BASIC don´t waste bytes

By JohnHassink

Ambassador (5655)

JohnHassink의 아바타

22-02-2011, 18:42

Yes, so when I use DEFINT A-Z, I don't have to DIM % since the arrays are automatically integers as well?

And if BASIC does not waste bytes, how come I lose memory when all I do is changing some 4's in the listing into 3's? oO

I do know that zero counts too.

It is like this:

0 = player arrays
1 to 4 = enemy arrays

By ARTRAG

Enlighted (6923)

ARTRAG의 아바타

22-02-2011, 19:03

pass to C
;-)