tepples wrote:As for clearing all RAM, it makes a lot of sense to me now, since you can declare a variable then rely on it being initialized to zero if you haven't used it yet.
And in fact, C guarantees that uninitialized variables at file scope are zero at the start of main().
I don't know guys, I'm still not convinced! =) The "if you haven't used it yet" part can be very tricky, because this condition may be true the first time you run a piece of code, but not at subsequent times... if this was the case, a possible bug would be pretty difficult to find. But if you instead initialized the variable at a convenient time, it would be correctly set whenever that piece of code was executed.
I'm not trying to convince anyone (as I'm sure nobody is trying to convince me) of anything, I'm just trying to express my point of view on variables and how to initialize them, since I seem to be alone on this one.
My current project has a pretty complex scrolling system, a pretty complex sprite system, and I can get away just fine by initializing memory only when I need it. I think this is the case because there really isn't a value I use that much that would justify writing it to every memory location. 0 is pretty much meaningless for most of my code...
Even when I (supposedly) do need to clear a block of RAM, such as the object slots used for active objects, I can usually get away with clearing just a small part of it. In the case of the object slots, each one has a byte that indicates the type of the object loaded there, and I know that the engine will check that value before anything else, and if I use 0 as a flag to indicate that the slot is empty, what do I care about the crap stored in the other bytes? And since I will surely clear those "object type" bytes before a level (re)starts, I see no need to clear that memory before that.
But I know this is only my case, and I guess I can accept that people out there will benefit from clearing it all on start up. This is not for me though... Even when programming in high-level languages I can't seem to assume any values on things I haven't initialized. OK, shutting up now.