Blitz3D+ Command Reference

ResizeBank bank,size

Parameters

bank - bank handle returned by CreateBank

size - new size of the bank in bytes

Description

Changes the size of a bank.

Existing contents are kept: growing a bank preserves everything and fills the new space with zeros, shrinking one keeps the first size bytes and drops the rest. The data may move in memory when the bank grows, which only matters if you handed the bank's memory to a DLL - re-fetch after resizing.

Handy for growable buffers, such as building a network packet or file image whose final size you do not know up front.

See also: CreateBank, BankSize, CopyBank.

Example

; ResizeBank Example
; ------------------

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

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

Print "Before: BankSize = "+BankSize(save)+" bytes"
Print "        hp = "+PeekShort(save,1)+"   score = "+PeekInt(save,3)

; ResizeBank grows (or shrinks) the bank - existing data is kept
ResizeBank save,22

Print ""
Print "After ResizeBank save,22:"
Print "        BankSize = "+BankSize(save)+" bytes"
Print "        hp = "+PeekShort(save,1)+"   score = "+PeekInt(save,3)+"   (data survived)"

; The new space is ready for a second record at offset 11
PokeShort save,12,180
Print ""
Print "Second record's hp stored at offset 12 = "+PeekShort(save,12)

FreeBank save

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

End

Index