[Function] : Memory allocation upon bind()

Hi All, Summary: Boost::bind() allocates memory on the heap. In my situaion it is necessary to use manual memory pool instead of heap allocation, to conform with real-time timing requirements. (no malloc() calls allowed in real-time code) A solution might be writing a custom allocator for the boost::bind()'s data, and use a pre-allocated memory pool with the "placement" new( void* ) to write directly into it. I've found that there was a discussion on std::allocator support for std::bind and std::function here: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2308.html I'm not very familiar with the internals of bind() and Function in general, hence advice is appreciated. What is the status of boost::bind() and custom allocators? Is there a chance this could work? Am I missing some "easy" workaround or solution? Thanks for reading, -Harry

On Tue, Jan 15, 2013 at 3:52 AM, Harry van Haaren <harryhaaren@gmail.com> wrote:
Hi All,
Summary: Boost::bind() allocates memory on the heap. In my situaion it is necessary to use manual memory pool instead of heap allocation, to conform with real-time timing requirements. (no malloc() calls allowed in real-time code)
A solution might be writing a custom allocator for the boost::bind()'s data, and use a pre-allocated memory pool with the "placement" new( void* ) to write directly into it.
I've found that there was a discussion on std::allocator support for std::bind and std::function here: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2308.html
I'm not very familiar with the internals of bind() and Function in general, hence advice is appreciated. What is the status of boost::bind() and custom allocators? Is there a chance this could work? Am I missing some "easy" workaround or solution?
Boost.Bind doesn't allocate memory, unless you bind some objects that do. Boost.Function does allocate memory to store the adopted function object, and it does support custom allocators. You can specify the allocator as the second argument of boost::function constructor.

On Tue, Jan 15, 2013 at 6:47 AM, Andrey Semashev <andrey.semashev@gmail.com>wrote:
Boost.Bind doesn't allocate memory, unless you bind some objects that do. Boost.Function does allocate memory to store the adopted function object, and it does support custom allocators. You can specify the allocator as the second argument of boost::function constructor.
I've not looked into the details about why malloc() was being called yet, as I've investigated different solutions to the situation I have at hand. If time permits I will look into custom allocators for Boost.Function, however it will not be in the near future. Thanks for your response Andrey, and apologies for not getting back sooner. -Harry
participants (2)
-
Andrey Semashev
-
Harry van Haaren