Banks are for high-speed operations, according to the manual, so I guess they are as fast as you can get.
I've never used them myself much, as I've not programmed that much in Blitz3D yet, but I'm planning to use them massively in my game I'm trying to create.
They can also reduce memory-usage.
In my game, I had an array to hold references to type-instances, which define my entire tile-based map.
But the size of the map needs to be 1000x1000 and each type-instance has 3 fields.
I checked TaskManager and the program used 46Mb of RAM, just creating the array and the type-instances.
But each field has a maximum value of 200, so I didn't need types where each field is an integer (4 bytes), I only needed bytes.
I then tried to create a bank of 3000000 bytes (1000x1000 mapsize x 3 fields per tile = 3Mb) and memory-usage dropped to 12Mb.
So using banks instead of types and arrays for my game, I'm reducing memory-usage by 34Mb.
Each character in a string is a byte, so a string with 20 characters will use 20 bytes.
You can store a string by first storing the length of the string, followed by the seperate characters (their ASCII-code) of the string.
If your strings are maximum 255 characters, then you can store the length in a byte.
This example has a string which consists of 16 characters.
The length of the string is stored first as a byte, so storing this string in a bank uses 17 bytes.
Graphics 800, 600, 0, 2
testbank = CreateBank(500)
; Write the given string to the bank at offset 10
a$ = "This is a string"
WriteStringToBank(testbank, 10, a$)
; Read the string from the bank which is located at offset 10
Print ReadStringFromBank$(testbank, 10)
Print ""
; Read each byte and character seperately
Print "Length = " + PeekByte(testbank, 10)
For i = 1 To PeekByte(testbank, 10)
Print PeekByte(testbank, 10+i) + " = " + Chr$(34) + Chr$(PeekByte(testbank, 10+i)) + Chr$(34)
Next
WaitKey()
End
Function WriteStringToBank(bank, offset, s$)
; Check if length if lower than 256
If Len(s$) < 256 Then
; Write the length to the bank as a byte
PokeByte bank, offset, Len(s$)
; Loop through the entire string
For i = 1 To Len(s$)
; Write each character's ASCII-code to the bank
PokeByte bank, offset + i, Asc(Mid$(s$, i, 1))
Next
EndIf
End Function
Function ReadStringFromBank$(bank, offset)
Local s$, c$
; Read the length of the string
Local length = PeekByte(bank, offset)
; ReCreate the string by reading each character's ASCII-code and merging them into one string
For i = 1 To length
; Read the ASCII-code and convert it to a character
c$ = Chr$(PeekByte(bank, offset + i))
; Add the character to the string
s$ = s$ + c$
Next
; Return the string to the calling routine
Return s$
End Function