CreateBank() zeros, ResizeBank() doesn't?
Blitz3D Forums/Blitz3D Beginners Area/CreateBank() zeros, ResizeBank() doesn't?
| ||
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? |
| ||
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. |
| ||
You could make the same argument about creating a bank... |
| ||
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. |
| ||
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. |
| ||
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. |
| ||
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.) |
| ||
ok. |