Boost logo

Boost :

Subject: Re: [boost] make_shared_array
From: Rhys Ulerich (rhys.ulerich_at_[hidden])
Date: 2012-11-02 10:02:24


>> 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


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk