如何经常从boost ::信号得到::可追踪? [英] How often to derive from boost::signals::trackable?
问题描述
在使用Boost.Signals,升压允许您从的boost ::信号::可追踪
为了缓解对象/连接生命周期管理(见的 Boost文档)。
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).
我在我的项目的早期阶段,我想,无论是从的boost ::信号::可追踪
在
I am in an early stage of my project and I am thinking, whether to derive from boost::signals::trackable
in
- 每一个新的类我写的,可能在未来使用Boost.Signals
- 或仅在课堂上,我相信,他们需要的功能的
可追踪
BAS E级
- every new class I write that might use Boost.Signals in the future
- or only in classes I am sure that they will need the functionality of the
trackable
bas e-class
有关届第一种方法的主要原因将是prevent我忘了从的boost ::信号得出::可追踪
。
The main reason for th first approach would be to prevent me to forget deriving from boost::signals::trackable
.
另外双deriverations像
Also double deriverations like
class Foo : public Base, public boost::signals::trackable
{
};
得到不必要的。
在另一侧,preventing内存泄漏不应该是一个主要的设计方面。测试和分析像Valgrind的工具应该被用来检测内存泄漏。
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?
推荐答案
注意 Boost.Signals2
取代 Boost.Signals
。它具有更加灵活和强大的跟踪机制一>。
Note that Boost.Signals2
supersedes Boost.Signals
. It has much more flexible and powerful tracking mechanism.
虽然文库的目的是提供多线程程序的线程安全的解决方案,该锁定开销可以在一个<一个可以避免href=\"http://www.boost.org/doc/libs/1_53_0/doc/html/signals2/tutorial.html#signals2.tutorial.signal-mutex-template-parameter\"相对=nofollow>单线程通过设置的环境的boost :: signals2 :: dummy_mutex
作为信号的内部互斥。
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.
这篇关于如何经常从boost ::信号得到::可追踪?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!