What are banks?

BlitzMax Forums/BlitzMax Beginners Area/What are banks?

BLaBZ(Posted 2010) [#1]
How are they used and what are their best practices?


ima747(Posted 2010) [#2]
Short answer, banks are memory spaces you can use for whatever...

I like to think of them as memory files. You can do all sorts of stream commands to them like you can with files, but since they're in memory rather than on disc they're nice and fast. One example of this is saving a pixmap to a PNG or JPEG to then transfer somewhere (like upload to a web site) You can just create a bank, save the pixmap as you would to a file but point it at the bank instead, and now you've got a handy chunk of PNG ready to be sent wherever.

I also use them to simplify combining multiple files. Example: I want to save 5 PNGs along with a bunch of settings to a file to use later. I save the pixmaps to PNGs in banks, I can then save the length of the banks and their content (stream to stream) to a file along with all my other data. When I retrieve it I just read the stored size so I know how big the bank is, create a bank that size and load the next data (the actual PNG) then I can load that to a pixmap or image or whatever. repeat for everything in that file.

There's plenty of other uses as well, that's just me :0)


BLaBZ(Posted 2010) [#3]
Wow that's awesome! Great answer ima747 thanks a lot :)


CS_TBL(Posted 2010) [#4]
You can also go dirty like this:

bank=createbank(8)
pokeint bank,0,1234
pokeint bank,4,10987

print peekint(bank,3)

Visually, what you do is inserting two ints (int=4 bytes) in 8 bytes (byte=*)like this:

[* * * *][* * * *]

then when reading out with peekint you get:

* * *[* * * *]*

so, a new Frankenstein composite of 2 int values!

Lovely ridiculous, probably useless as well, but it shows that there are no rules with banks.


xlsior(Posted 2010) [#5]
Another use is for things like file encryption: you can have an encrypted file on disk, laod it into a memory bank, then decrypt the memory bank (either in place or into another memory bank), and then point your normal file load routines to the decrypted memory bank.

That way you don't need to write un-encrypted temporary files to the harddrive where a user might see or copy them.


Dabhand(Posted 2010) [#6]
Another use is that you store your money in them, you can even get loans and insurance and things too!

*Dabz gets his coat*

Dabz


markcw(Posted 2010) [#7]
dodgy post.


markcw(Posted 2010) [#8]
I have written an update for brl.bank docs which you can get here:
http://www.blitzmax.com/logs/userlog.php?user=8652&log=1737 [b3ddocspatch199.zip]

This is a non-source copy, so if you do a rebuild docs it will disappear. Extract to BlitzMax/docs.


Czar Flavius(Posted 2010) [#9]
What does the update add?


Dabhand(Posted 2010) [#10]

What does the update add?



New documentation for Blitz Banks... I'm hazarding a guess there mind Mr C! ;)

Dabz


markcw(Posted 2010) [#11]
All you have to do is download it to find out.


Czar Flavius(Posted 2010) [#12]
Oh, "docs", didn't see that!