CreateBank() zeros, ResizeBank() doesn't?

Blitz3D Forums/Blitz3D Beginners Area/CreateBank() zeros, ResizeBank() doesn't?

octothorpe(Posted 2005) [#1]
From my experimentation, I've found that bytes allocated by CreateBank() are set to zero, while new bytes claimed by expanding a bank via ResizeBank() often contain garbage.

Are my findings correct, or are there gotchas I don't know about?


big10p(Posted 2005) [#2]
Yeah, you appear to be right. I'm a bit surprised by this but I expect it's done this way for speed reasons. If you resize a bank it's a fair assumption that you'll then fill the new bytes with data, making zeroing them a waste of time.


octothorpe(Posted 2005) [#3]
You could make the same argument about creating a bank...


VP(Posted 2005) [#4]
As good coding practice, you should assume that any newly allocated storage contains garbage until you initialise it. If you carry that thinking with you through to C/C++, you will avoid a lot of trouble.


big10p(Posted 2005) [#5]
You could make the same argument about creating a bank...
True, which is why I said I was surprised. However, createbank is done once whereas resizebank can be done many times (probably inside a main loop), so speed of execution is more of an issue, I guess. It is inconsistent, though.


jfk EO-11110(Posted 2005) [#6]
I think it's a good thing that it doesn't zero the bank. because this way you can increase the size of an existing bank without to save its content in a temporary buffer.


octothorpe(Posted 2005) [#7]
jfk: We're talking about newly assigned bytes - existing data is always preserved for you (presumably via a DMA copy if the bank needs to be repositioned on the heap.)


jfk EO-11110(Posted 2005) [#8]
ok.