Boost logo

Boost Users :

From: Markus Werle (yg-boost-users_at_[hidden])
Date: 2003-02-10 12:29:32


Douglas Gregor wrote:

> On Monday 10 February 2003 07:19 am, Markus Werle wrote:
>> Before I dig in that code: where do those copies come from?
>> Is that the normal behaviour triggered ny operator() or is that a
>> hint that I use them the wrong way?
>
> operator() will not make any copies. The overhead of operator() comes from
> calls through function pointers.
>
> The most likely reason I can think of for the multitude of copy
> constructions after the array is built is that you are passing
> boost::function2 objects to routines that take function objects by value.
> Unfortunately, this is the common way to pass function objects, e.g.,
>
> template<typename F> void do_something(F f) { ... }
>
> If you are using the C++ standard library algorithms,

Yeah, that's it. std::algos everywhere.

> that may be your culprit.

I think yes.

> You can pass a "reference" to those algorithms by changing 'f'
> parameters to:
> boost::bind(ref(f), _1, _2)

Do I need this only in the outermost binding level
(I have nested boost::functions) or do I have to
apply "ref" also to the original (true, existent) functions
at the leaves of the functor tree?

Markus


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net