[cfe-dev] Proposed C++ optimization with big speed gains with big objects
Klaim - Joël Lamotte
mjklaim at gmail.com
Thu Sep 27 03:32:55 PDT 2012
On Thu, Sep 27, 2012 at 12:51 AM, Ladislav Nevery <neuralll at gmail.com>wrote:
> Actually the sample you provided will work without problem.
> Since switch works only on first assign(after default constructor)
> TextFile textfile; // default constructor doing nothing
> textfile=TextFile("c:\test1.txt"); // = we call destructor doing nothing
> and placement new
> textfile=TextFile("c:\test1.txt"); // standard temp copy + operator
> But I see the point if you put code logic to default constructor then yes
> first assign will not happen. You use switch to remove copy from arrays
> init. So yes actual code change is needed in this statistically marginal
> Anyway code logic (opening files etc) in default constructors is BLASPHEMY
> :D such people actually deserve to being punished.
> Punishing them a bit more is actually good thing ;D Lets call it feature
I'm sorry I don't understand at all what you mean here.
I'm saying, taking the exact code I proposed, not changing it by adding a
default constructor, this expression:
TextFile a ("a.txt");
TextFile b ("b.txt");
a = b; //copy the content of b.txt in a.txt
Would have, using your change, a different semantic than what the standard
propose because there would be file closing and opening where I didn't want
The type is specifically written to avoid closing and opening files until
the instances are really out of scope or explicitely deleted.
Or did I misunderstand your proposal?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the cfe-dev