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

Ladislav Nevery neuralll at gmail.com
Mon Sep 24 16:36:19 PDT 2012

...The old state of city[1] may need to be 
cleaned up.  Thus, you would also have 
to call city[1].~Skyscapper(), first. 

I see this more like interesting new feature. The ability to recreate object
just by reinvoking constructor with new parameters is welcome adition at
least for me.

...if SkyScrapper::SkyScrapper(const char *) 
throws, the state of city[1] is undefined. 

The behavior is already defined as part of c++ iso standard in "placement
new" section.
The moment user decided to invoke constructor he agreed to loose old object
so I don't see problem there.

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

yes there is exatly like in placement new case. since destructor handles
only dynamic members not object itself that is statically preallocated and
can't be deallocated alone.

The destructor situation is exactly the same as if some constructor throws
during any static array creation.
Only dynamic memory members can be undefined. And this situation is no
different from todays implementation of static arrays so no different
behavior there either.

I think by using the same code that placement new generates behavior will be
exactly as in c++ iso standard defines for placement new.

I wouldnt worry about =& copy or =&& move operator not being called in this
case of array element creation since that was the whole purpose of the
That is creating in array as it should had been in c++ from the start.
Instead of usual inefficient create temp and copy (&= ) or create temp and
half copy(static mem) and half move(dynamic mem) in (=&&).

Now using such optiomization switch will be more popular since  you just
recompile any old code without any  change and get performance boost that
you can't get by writing zillion of duplicite && operator variants since
they solve only heap.

Thx for very insightful look at issues. If only I knew where to start and
where is = to array in clang or placement new implementation.

View this message in context: http://clang-developers.42468.n3.nabble.com/Proposed-C-optimization-with-big-speed-gains-with-big-objects-tp4026886p4026905.html
Sent from the Clang Developers mailing list archive at Nabble.com.

More information about the cfe-dev mailing list