
2 Nov
2012
2 Nov
'12
2:02 p.m.
Isn't this a case of "it depends"? Sometimes it's completely wasted cycles, sometimes it's essential...
It is. Olaf is arguing that there is never a need to initialize an array when the elements are of a built-in type such as double or T*.
...though this doesn't uniformly hold true for, e.g., doubles. In numerical algorithms, it can sometimes be natural to additively accumulate on each iteration. Initialization to zero on allocation can serve to a) simply expressing an algorithm and b) pull the data into cache prior to a compute loop. Not that a simple memset after the allocation wouldn't suffice, but the expressiveness of "give-me-a-zeroed-array-of-doubles" as a single statement is crisp at times. - Rhys