[cfe-dev] Proposed C++ optimization with big speed gains with big objects

Steven Watanabe watanabesj at gmail.com
Mon Sep 24 12:32:39 PDT 2012


On 09/24/2012 03:37 AM, _ wrote:
> Hi guys
> Hi guys
> I wana discuss proposed optimization step(optional switch?) to c++
> compiller that would make old and new code in some cases order of
> magnitude faster by just pure recompilation.
> ...After all those attempts to store anything via = without waste I
> think that compiller should do "placement new" transparently for us
> whenever he encounters = on movable object.  Instead of forcing us to
> implement zillion && operators that solve only heap side of problem.
> Deciding what kind of "this" object should use is easy since static
> analysis deciding what object is movable is already part of new
> compillers as part of support for &&.
> Skyscrapper city[1000];                         // instead of temp
> city[1] = Skyscrapper("Empire State Building"); // compiller should
> use &city[1] as this pointer

This is seriously problematic in most cases.
The old state of city[1] may need to be
cleaned up.  Thus, you would also have
to call city[1].~Skyscapper(), first.
then, if SkyScrapper::SkyScrapper(const char *)
throws, the state of city[1] is undefined.
There's no way to invoke the destructor
/after/ calling SkyScrapper, since that
would leave two objects at the same address
while the constructor is running.  Basically,
there's no way to make this work so that
all resources are allocated and freed
correctly.  This isn't even taking into
account the fact the C++ specifies exactly
how this code is supposed to behave, and
skipping the assignment operator is not licit.

In Christ,
Steven Watanabe

More information about the cfe-dev mailing list