我应该选择哪个 C++ 信号/插槽库?

Which C++ signals/slots library should I choose?(我应该选择哪个 C++ 信号/插槽库?)

本文介绍了我应该选择哪个 C++ 信号/插槽库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在不使用 QT 的项目中使用信号/插槽库.我有非常基本的要求:

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

  1. 用任意数量的参数连接两个函数.
  2. 信号可以连接到多个插槽.
  3. 手动断开信号/插槽连接.
  4. 不错的性能 - 应用程序是基于框架的(即不是基于事件的),我想在每个框架中使用连接.

我读过 libsigc++ 和 Boost.Signals 的比较.我还读过 Boost.Signals 性能不佳.但是,我知道还有其他库,但我仍然不确定应该选择哪个库.

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?

推荐答案

首先,无论如何都要尝试使用 boost::signal.在您尝试使用您的应用程序的特定情况之前,不要认为它不够快

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

如果它不够高效,也许像 FastDelegate 之类的东西适合您需要?(我没有尝试,但听说在 boost::signal 似乎不适合的某些情况下这是一个不错的解决方案).

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).

这篇关于我应该选择哪个 C++ 信号/插槽库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:我应该选择哪个 C++ 信号/插槽库?

基础教程推荐