Posted: Tue Jun 26, 2007 7:33 pm
I can think of an example that would be inefficient in terms of initialization: arrays of objects in C++. Each element of such an array is default-constructed when the array is allocated. I'm not sure how common this is in practice (I tend to use vectors of pointers to objects myself).That depends how you use the array. If it's an array of bytes used for a buffer or something, then you never initialize it (you just load data into it and keep track of how much data has been loaded in). If it's an array of structures where the structures are used in order it's the same thing (you have a variable that keeps track of how many entries are in use, where entries that aren't in use aren't initialized and don't need to be filled with zero). If it's an array of structures that aren't used in order, then you have some sort of "used/unused" field in the structure and this field does need to be initialized to "unused" (but not necessarily set to zero) while the other fields are left uninitialized (and not filled with zero).