Help with Banks

BlitzMax Forums/BlitzMax Programming/Help with Banks

Rico(Posted 2013) [#1]
I like to use banks to save game maps. I only have a basic grasp of them.

I now want to use a bank to save a map I have made which depending on what you do in the map-editor the size of it will change each time. I normally just make a fixed size bank and save to that but now I need one that changes size - sometimes it will need to increase in size, at other times it will need to reduce in size. How do I do this? I have looked at the available instructions and there is a Resize command, but there is no explanation of exactly how you use it or what it does

Can anyone help? thank you.


xlsior(Posted 2013) [#2]
A bank is basically just a contiguous block of memory, x bytes, one-dimensional. It's basically just a fixed-length string that you can address directly in memory.

For maps it may be easier to use a 2-dimensional array, where you can have a distinct x and y dimension


Sub_Zero(Posted 2013) [#3]
Function ResizeBank( bank:TBank,size )

Where size is the total amount size

you could do:

ResizeBank(bank, BankSize(bank) + more_bytes)

For grids, you could resize the bank to (COLUMNSIZE*ROWSIZE) and then access data with x + (y*COLUMNSIZE)


Rico(Posted 2013) [#4]
Thanks Xlsior - I am using an 2D array to store the map in memory but I save it into a bank.

@Sub_zero - Thank you, does resize just add the extra bytes to the end of the bank?


Sub_Zero(Posted 2013) [#5]
No you'll have to specify the full length


Brucey(Posted 2013) [#6]
does resize just add the extra bytes to the end of the bank?

It will use a new chunk of contiguous memory, copying the data from the old to the new one. So, if you have a large amount of data, you don't want to be resizing very often if you can help it.


Rico(Posted 2014) [#7]
Ok thanks very much for all the help. I should be ok now.