Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8187685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T02:38:44+00:00 2026-06-07T02:38:44+00:00

Boost::bind documentation states: By default, bind makes a copy of the provided function object.

  • 0

Boost::bind documentation states:

By default, bind makes a copy of the provided function object. boost::ref and boost::cref can be used to make it store a reference to the function object, rather than a copy.

I am seeing excessive news and deletes in my code when I use boost::bind with a pointer to a member function. The documentation is unclear to me whether boost::bind(&classname::functionname,…) makes a copy of the function.

Or maybe the question makes no sense and as it is converting a member function into a function object it obviously has to new the function object.

So my question is there a way I can bind to a member function and avoid the new and delete?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T02:38:45+00:00Added an answer on June 7, 2026 at 2:38 am

    According to my experiments (boost 1.49), boost::bind does not use dynamic memory for its own implementation. With this code

    #include <boost/bind.hpp>
    
    int f(int a , int b) {
      return a>b ? a+b : a-b;
    }
    
    int main()
    {
      auto a = boost::bind(f, _1, 2);
      return a(0);
    }
    

    I tried breaking on operator new variants in gdb and it didn’t fire. So I suspect your problem is actually that boost::bind is making copies of either the bound arguments (compare the output of these two snippets) or the call arguments. Search for something among these that could allocate memory while copying, and try to get rid of it.

    If you’re using a C++11 compiler, you can get away with boost::bind completely and use a lambda function instead. The example would be transformed to

    auto a = [&](int a1) { return f(a1, 2); }
    

    That would only copy if you’d capture objects by value.

    EDIT: With the code you posted, try changing the line in question to

    TConstIterator pIt = std::find_if(rtContainer.begin(), rtContainer.end(), 
      boost::bind(&TValueType::bSameSocket, boost::cref(rtData), _1));
                                            ^^^^^^^^^^^
    

    That should make it better; report if it doesn’t.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Other than boost (Bind & Function), how can I dynamically call a function in
I am trying to lean boost::bind, boost::lambda libraries and how they can be used
In Boost::Spirit, how can I trigger an expectation_failure from a function bound with Boost::Bind
Using boost-bind , the resulting boost-function may receive more arguments than the bound object
boost::bind overloads several operators for its placeholders: For convenience, the function objects produced by
I have some C++ code #include <cstdio> #include <boost/bind.hpp> #include <boost/function.hpp> class A {
want to pass boost::bind to a method expecting a plain function pointer (same signature).
I am trying to use boost::bind with a boost::function using this. It seems a
I have just been working with boost::bind and boost::function and noticed the following behaviour
Is there any way to make boost::bind work with std::fill ? I tried the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.