Boost logo

Boost :

From: Howard Hinnant (hinnant_at_[hidden])
Date: 2004-07-06 12:07:37


On Jul 6, 2004, at 11:37 AM, David B. Held wrote:

> "Howard Hinnant" <hinnant_at_[hidden]> wrote in message
> news:D131A1F4-CEE6-11D8-ACE3-003065D18932_at_twcny.rr.com...
>> [...]
>> I initially viewed call_traits as a way to optimize whether a type
>> should be passed by const ref or by value. But I was mistaken.
>> The real value was in passing/returning reference types without
>> bumping into the reference-to-reference problem.
>
> So are you saying that call_traits is *not* useful for said
> optimization? If so, why not?

For it to make a significant difference in performance, say for passing
a parameter, the function would have to be very short - short enough
that it should be inlined.

On Metrowerks Pro 9.2 / Mac I've just run the following experiment:

inline
int foo1(int i)
{
        return i;
}

inline
int foo2(const int& i)
{
        return i;
}

int main()
{
        int i = 1;
        return foo1(i);
}

I've looked at the generated (optimized) assembly of main, using both
foo1 and foo2. The assembly is identical in both cases. No doubt I
could come up with examples where the assembly is different. But I'm
having more trouble coming up with a situation where the performance
difference is enough that I'd want to start lacing my generic code with
call_traits for this purpose. However if you have such examples, I'm
interested in pursuing this further.

-Howard


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk