Blitz3D+ Command Reference

BankSize ( bank )

Parameters

bank - bank handle returned by CreateBank

Description

Returns the size of a bank, in bytes.

Valid offsets in the bank run from 0 up to BankSize-1. The size only changes when you call ResizeBank.

Typical uses: saving a whole bank with WriteBytes bank,file,0,BankSize(bank), or bounds-checking your own offset arithmetic before a Peek or Poke.

See also: CreateBank, ResizeBank, CopyBank.

Example

; BankSize Example
; ----------------

; One player save record needs 11 bytes:
; flags (byte=1) + hp (short=2) + score (int=4) + x_pos (float=4)
roster=CreateBank(11)

; Pack the first record
PokeByte roster,0,5
PokeShort roster,1,250
PokeInt roster,3,1234567
PokeFloat roster,7,17.25

; BankSize returns the current size of a bank in bytes
Print "Roster holds 1 record: BankSize = "+BankSize(roster)+" bytes"

; Grow the bank to make room for a second player's record
ResizeBank roster,22
Print "After ResizeBank for 2 records: BankSize = "+BankSize(roster)+" bytes"

; BankSize is handy for loops over every byte of a bank
count=0
For i=0 To BankSize(roster)-1
    If PeekByte(roster,i)<>0 Then count=count+1
Next
Print "Non-zero bytes in the bank: "+count

FreeBank roster

Print ""
Print "Press any key to close the example"
WaitKey

End

Index