TBank not clean always at creation?

BlitzMax Forums/BlitzMax Beginners Area/TBank not clean always at creation?

Danny(Posted 2011) [#1]
I've always expected a memory bank to be 'empty' (filled with 0's) when you create or even re-size it. And I always used them as such - without problem (B3D & BMax).
But currently it seems that TBanks aren't always 'clean' to start with, but could have 'random data' in them: See the example code below..

Has this always been so (am I going crazy? ;) or is this a bug or 'new feature' of some sort? I'm using BMax 1.41..

Cheers,
Danny

Local bank:TBank = CreateBank(1000)
Local numDirty% = 0

For Local i% = 0 To bank.Size() -1
	If bank.PeekByte(i) <> 0 Then numDirty :+ 1
Next
DebugLog "Done: " +numDirty+" / 1000 dirty bytes encountered"
WaitKey()
End



Danny(Posted 2011) [#2]
Then what is the quickest way of clearing (filling with 0's) a bank?
I found that PokeLong works about 4 to 5 times faster than using PokeByte to the same effect..

D.


ImaginaryHuman(Posted 2011) [#3]
PokeInt should be faster?


Ole JR(Posted 2011) [#4]
Maybe something like:
MemClear(bank.Lock(), bank.Size())
bank.Unlock()



Czar Flavius(Posted 2011) [#5]
If you are not going to read any data from the bank before writing data to it, then you don't need to clear it. For example, if you are storing a file into the bank then there is no point to zero-ing it first as the junk will be overwritten.

You could try using an array instead. Blitz arrays are zeroed automatically.


Danny(Posted 2011) [#6]
@CZar: I use the bank for (new) level data, so I expected things to be clear (0) at first.
@Ole JR: Good tip - this is indeed a super fast method, cheers!

Last edited 2011