This is a discussion on Re: Fast argument passing - c++ ; On 26 nov, 01:14, Mathias Gaunard <loufo...@gmail.com> wrote: > On 25 nov, 18:07, courp...@gmail.com wrote: > > > if ( sizeof(Type) > sizeof(Type*) ) > > pass by ref to const > > else > > pass by value > ...
On 26 nov, 01:14, Mathias Gaunard <loufo...@gmail.com> wrote:
> On 25 nov, 18:07, courp...@gmail.com wrote:
>
> > if ( sizeof(Type) > sizeof(Type*) )
> > pass by ref to const
> > else
> > pass by value
>
> This is quite naive.
> The type could be small but have an expensive copy constructor.
>
> I suppose you only want to pass-by-value for objects with trivial copy
> constructor.
Yes, you guessed correctly, I'm interesting only about POD / data
structures that can be copied in a raw way.
I generalized too much the problem in my post and I forgot to mention
that aspect.
> Also, it may be interesting to pass objects sized of two words by
> value too.
Indeed, I thought about (sizeof(Type) > sizeof(Type)*n) where n = 2
or even 3 or 4 could work, but this is somewhat less provable than the
first condition. In fact I would want to always have an equal or
superior performance over just a pass by value, or just a reference to
const.
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]