Boost logo

Boost Users :

From: Trent Hill (trent.hill_at_[hidden])
Date: 2005-01-04 22:11:19

I was recently surprised to find that boost::bind seems to copy
arguments a number of times when called. For example, this program:

     class C
         C() {}
         C(const C &c) : data( { std::cout << "C(const C &c)\n"; }
         boost::array<char, 4000> data;

     void foo(const C &) {}

     main(int a_argc, char **a_argv)
         C c;
         boost::bind(&foo, c);
         return EXIT_SUCCESS;

results in this output (Visual C++ .NET with /O2):

     C(const C &c)
     C(const C &c)
     C(const C &c)
     C(const C &c)

Four copies - I had hoped to only see a single copy. Logically, there
doesn't seem to be a need for more than one copy. Is there an
implementation issue that requires this many copies?

I was hoping to use bind with some moderately weighted objects, however
the number of copies that seem to occur may be prohibitive for me. (I
realise that dynamically allocating objects and passing around pointers
is an alternative but I'd rather avoid that if possible.)

Any thoughts?
Thanks, Trent.

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at