How does boost implements signals and slots?

2020-03-08 07:16发布

问题:

To continue another question, lets ask this:

How does Boost implement the signals/slot mechanism?

See: How signal and slots are implemented under the hood? http://www.boost.org/doc/libs/1_40_0/doc/html/signals.html

回答1:

here's an interesting snippet from this gamedev.net thread to get the discussion rolling

Original post by Spoonbender So, bonus question: What causes boost::signals to be that much slower?

It looks like there are a couple of biggies. First, despite the fact that boost::signals isn't threadsafe, it enters and leaves critical sections a couple of times. Secondly, there's this named-slots thingy which seems to result in overly complex data structures which take a long time to iterate over. And then there's a lot of nickel-and-diming from various housekeeping things it does. Finally, the individual calls have much higher overhead because of boost::bind's runtiminess. It's all functionality that I'm sure someone has a need for, but I don't.