Memory Banks

Blitz3D Forums/Blitz3D Programming/Memory Banks

Yue(Posted 2013) [#1]
One thing I still do not understand well are banks of memory, which is the difference in relation to the variables or constants and are much faster in data obteción memory bank?


virtlands(Posted 2013) [#2]
Hmmm, my theory is the following, (when comparing data speeds) :

(a) String variables are the slowest form of all, (such as A$="string..data").

(b) Arrays such as DIM A(10), Global B[10] are the fastest.

(c) Banks, such as b=createbank(10), can be just as fast as arrays, but it depends on how you use them.

(d) In some cases, banks can be much faster than array usage, when using the following commands:
CopyBank, ReadBytes, WriteBytes.

(e) Doing a command such as " pokebyte b,offset,value " should be about the same speed as " a(5)=100 " .

These are just my ideas. I haven't had time to prove them.
-------------------------------------------------------------------
As usual, if you want the check on the timing of various code, put it in a timing loop to check it.

For example, do this

t1 = millisecs()
for z=1 to 1000
code
code
code
code
code
code
code
code
code
code
next
t2 = millisecs()

ET = (t2-t1) ;=elapsed time in milliseconds

Within the loop, put in a predetermined count of "code", such as 100 of them, for example.

Remember, that the "for", and "next" commands (by themselves),
also take a tiny amount of time. That's why, for accuracy, "code" is repeated.
-------------------------------------------------------------------------
Here is another idea of mine for checking code timings; I'm not sure how
great this shall work, but it looks good.

For an accurate timing, first calculate the timing of an empty
loop, and then calculate the timing of the loop with "code" in it.

Local t[4]
const MaxLoop =100000 ;; Adjust this number to your liking.
ET# = 0.0 ;; elapsed time
WaitKey() ;; Touch a key to start

t[1]=MilliSecs()
for z=1 to MaxLoop
next
t[2]=MilliSecs()

t[3]=MilliSecs()
for z=1 to MaxLoop
code
next
t[4]=MilliSecs()

ET = (t[4]-t[3])-(t[2]-t[1]) ; accurately compute the elapsed time of repeated "code"

or
ET = t[4]+t[1]-t[3]-t[2]

{ As an option, do ET = ET*1.0/MaxLoop, to find the timing of 1 "code", but it's not vital. }


Yue(Posted 2013) [#3]
Ok, thank you very much. Now if I have a data that evaluates the player's maximum health by 100, which goes better use.

Local Vidamax% = 100;

Local Bank% = CreateBank (1)
Bank PokeByte%, 0.100; Byte 0, 255


virtlands(Posted 2013) [#4]


The first version is both faster and simpler, (but there's not much difference).

Local Vitamax=100 ;; is simpler

Local Bank = createbank(1)
PokeByte Bank, 0,100


Who was John Galt?(Posted 2013) [#5]
A bank is just an abstraction of a block of memory. It's similar to an array, but you write all different kinds of data to it, unlike arrays that just take multiple instances of the same data type.