Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

boost - Which C++ signals/slots library should I choose?

I want to use a signals/slots library in a project that doesn't use QT. I have pretty basic requirements:

  1. Connect two functions with any number of parameters.
  2. Signals can be connected to multiple slots.
  3. Manual disconnection of signal/slot connection.
  4. Decent performance - the application is frame-based (i.e. not event-based) and I want to use the connections in each frame.

I've read a comparison between libsigc++ and Boost.Signals. I've also read that Boost.Signals suffers from poor performance. However, I know there are other libraries and I'm still not sure which library should I choose.

Are there any recommendations for a signals/slots library?

question from:https://stackoverflow.com/questions/359928/which-c-signals-slots-library-should-i-choose

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

First, try with boost::signal anyway. Don't assume it will not be fast enough until you try in your specific case that is your application

If it's not efficient enough, maybe something like FastDelegate will suit your needs? (i did'nt try it but heard it was a nice solution in some cases where boost::signal don't seem to suit).

Anyway, if in your application use the signal each frame, it may be worth to replace the signal system by something more simple, like a container that hold objects/functors that will be called each frame. Signal is more made to allow immediate "events" management than to make a loop cycle dynamic (allowing changing the functions called each frame). (I have my own solution (UPDATE: it's very old and archaic now) that i heavily use in a game and for instance i've no problem with the performance, so maybe something similar could help).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...