c++boostcoding-styleboost-signalsboost-signals2

How often to derive from boost::signals::trackable?


When using Boost.Signals, boost allows you to derive from boost::signals::trackable in order to ease object/connection lifetime management (See the boost documentation).

I am in an early stage of my project and I am thinking, whether to derive from boost::signals::trackable in

The main reason for th first approach would be to prevent me to forget deriving from boost::signals::trackable.

Also double deriverations like

class Foo : public Base, public boost::signals::trackable
{
};

get unnecessary.

On the other side, preventing memory-leaks shouldn't be a main design-aspect. Testing and profiling tools like valgrind should be used to detect memory leaks.

Which approach is more suitable for growing projects?


Solution

  • Note that Boost.Signals2 supersedes Boost.Signals. It has much more flexible and powerful tracking mechanism.

    Although the library aims to provide a thread-safe solution for multi-threaded programs, the locking overhead can be avoided in a single-threaded environment by setting boost::signals2::dummy_mutex as signal's internal mutex.