Does boost :: bind increase overhead?

I am currently working on network software. It has one main class server, which obviously represents a server instance.

A serverinstance can send requests, and the user gets a callback response.

The code looks like this:

class server
{
  public:
    typedef boost::function<void (int duration)> callback_func;

    void send_request(endpoint& ep, callback_func cb);
};

Now let me say that, as a user, I want the callback to know about the instance that called it, I can do the following:

void mycallback(const server& sv, int duration) { ... }

server sv;
sv.send_request("localhost", boost::bind(&mycallback, boost::ref(sv), _1));

But I wonder: is there any overhead? Will calls be mycallbackslower than using a “normal” call?

Thank.

: , , typedef : typedef boost::function<void (const server& sv, int duration)> callback_func;, boost::bind , , . , boost::bind.

+5
4

, . , , , operator(), . , ? , . 10 . , , .

, . , . , , , boost::function. , ( ).

+5

boost::bind , , , boost::function , . boost::function , .

PS. Tamás Szelei: 10 .

+5

, ( ) .

, boost:: function ( boost::function). , .

mycallback . , . ( ), mycallback :

void mycallback( .1. ) { .2. }

struct mycallback {
    void operator()( .1. ) const { .2. }
};
+2

Remember that boost :: bind calls a copy of the functor. This can be very significant. For my operating system, news and deletions are very expensive. See the documentation for boost :: bind for ref () and cref () links. I believe member functions also call copies of functions, but there is no documentation on this.

+1
source

All Articles