Cleaned up C++
Andrei Alexandrescu via Digitalmars-d
digitalmars-d at puremagic.com
Sat Apr 25 19:55:09 PDT 2015
On 4/25/15 3:23 PM, John Colvin wrote:
> On Saturday, 25 April 2015 at 21:26:25 UTC, Andrei Alexandrescu wrote:
>> On 4/22/15 1:36 PM, John Colvin wrote:
>>>
>>> Is it even possible to contrive a case where
>>> 1) The default initialisation stores are technically dead and
>>> 2) Modern compilers can't tell they are dead and elide them and
>>> 3) Doing the initialisation has a significant performance impact?
>>>
>>> The boring example is "extra code causes instruction cache misses".
>>
>> I've seen statically-sized arrays causing problems. -- Andrei
>
> Care to outline an example?
Many examples have to do with sentinel-terminated buffers. Start with e.g.
char buf[1024] = void;
buf[0] = 0;
...
The rest of the function makes sure it keeps the invariant that the
buffer is zero-terminated. This is difficult for compilers to divine
(never saw any to do so). So you have either code that's officially
unsafe because it uses uninitialized data, or slow code because it
zeroes the entire kilobyte.
No more need to get into details here, because... IT'S HACKATHON TIME!
I'll post my ideas next.
Andrei
More information about the Digitalmars-d
mailing list