Re: cloning a basic type efficiently
terry wrote:
"alex" <alex.shulgin@gmail.com> wrote in message
Hm... have you turned off debugging when compiling that thing? I
remember having seen VS not inlined anything when in debug mode... :-)
No question - all optmisation is switched on - my loops tend to be of the
order of 3 billion which would kill debug mode; I have even used the
options for enforce inline - but as these are functions declared in header
files this is not officially nessecary. The timings are similar fo rg++ in
cygwin so I think I must have something in my ocde that is forcing
somethng
to be written to memory and stopping the use of registers at some point.
But
I cnnot see where.
Any real answer will depend on the compiler, but several
suggestions...
-- Don't define any of the functions the compiler will generate
automatically. It depends on the compiler, but it is
generally easier for the compiler to know that there is
nothing special in code it generates than in code you write.
Note too that the presence of some user defined functions
(copy constructor, but perhaps others as well, I'm not sure
of the exact rules) will prevent g++ from passing/returning
the value in a register.
-- Try using pass by value everywhere, instead of references.
This is very compiler dependant, but generally, a reference
is implemented as a pointer, pass by reference as taking the
address, and the fact that the address has been taken will
inhibit keeping the object in a register. The optimizer may
later get rid of all the addressee, and figure out that it's
OK anyway, but then again, it may not. In this case, a lot
of extra copying may actually improve performance, since
having the copies avoids pinning the variable to a specific
memory address.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orientie objet/
Beratung in objektorientierter Datenverarbeitung
9 place Simard, 78210 St.-Cyr-l'Icole, France, +33 (0)1 30 23 00 34
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]