Boost logo

Boost :

Subject: [boost] [call-traits][param_type] why is sizeof(void*) chosen as the limit for passing by value?
From: Thorsten Ottosen (nesotto_at_[hidden])
Date: 2010-04-15 12:06:48


Hi Boosters,

It seems to me that many other slightly larger types could benefit from
pass by value. For example, I rarely write

   foo( const double& );

but always

   foo( double );

So param_type<T>::type don't even follow this guideline.

I tried a simple example program for the auto_buffer (vector like) class
I'm implementing:

#include <boost/auto_buffer/auto_buffer.hpp>

int main()
{
     boost::auto_buffer<double> buf( 2001u );
     buf.push_back(42.);
}

When I pass by value in push_back(), the assembler is somewhat
different, and as far as I can tell, better. Basically my compiler
(vc9) can inline the load of 42. into push_back() whereas in the call
by reference, the parameter is passes by a pointer (in a register).

In the by-value version the compiler is able to optimize away completely
the call to alllocate and delete memory whereas this is not so for the
by-reference version.

This makes me wonder why we shouldn't expect e.g. std::pair<int,int> and
std::bitset<64> to
be easily passable in registers.

With this in mind, I think we should consider changing the limit for
param_type to sizeof(long double) or even 2*sizeof(int). Of course,
we should only pass types with a trivial assignment operator by value.

Any thoughts?

-Thorsten


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