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

Ladislav Nevery neuralll at gmail.com
Wed Sep 26 01:47:41 PDT 2012


the idea was to enable it just for first initialization. ie we mark array
elements last constructor was default one
knowing this we can return object to previous state like it was previous
copy case.

Skyscrapper city[1000];
city[1] = Skyscrapper("Empire State Building"); 


              city[1].~Skyscraper(); // release member resources aquired by
default constructor
try new (&city[1]) Skyscraper("empire state building"); catch(...) { //
cleanup
     new (&city[1]) Skyscraper()  // reaquire member resources aquired by
default constructor
     throw;
}

this will make code behave like in standard. ie
in exception handler you get object in state after default initialization
yet preventing default copy.

yes state machine will change. ie if you were doing let's say gets(from
file) in default constructor. you will get change in code logic since one
more default constructor was invoked once more.
but this is bad design.

I think if frist line of documentation of such switch will be 
"by using this switch default constructor will be recalled during exception
to restore object to previous state"

Now about how relevant is this previous object state when exceptions start
flying around from constructors ?

statistically 99% of exception in constructor will happen due to memory
exhaustion(we are allready doomed) .
statistically 99% of member pointers in code around you were not smart
pointers (we are allready doomed) 

So I think it shall be tested since advantages massively outweight pretty
much hypotetical disadvantages.




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



More information about the cfe-dev mailing list