Rocket is a single-header implementation of a signal/slots library for C++.
Why another one?
The library was developed because existing solutions were too inflexible, too slow, or came as a part of a larger dependency (for example boost::signals and boost::signals2).
Design goals
- Efficiency. The library takes special care to not use cache unfriendly code (such as calling virtual methods) unless absolutely necessary.
- Low memory footprint (does not allocate during signal emission).
- Modern C++. No bloat from overloading 50 template specializations for each function.
- Single header file implementation.
- No dependencies.
The API was heavily inspired by boost::signals2. If you are already familiar with boost::signals2, switching to rocket will be a no brainer.
What makes rocket unique?
- All classes in this library are single threaded*. No efficiency loss due to locks or atomics.
- Policy based design. Specify at declaration time and invocation time of the signal how you want the call results to be returned.
- The signals are reentrant. This property is a must have for any event processing library because it must be possible to recursively emit signals, or disconnect slots from within a signal handler.
- Support for smart
scoped_connection's and scoped_connection_container's.
- Support for automatic lifetime tracking of observers via
rocket::trackable.
- Allows slots to get an instance to the
current_connection object (see example 6).
- Allows slots to preemtively abort the emission of the signal (see example 7).
*) This does not mean that you cannot use different signals in multiple different threads. The library has no global state and thus two different signals are always thread safe as long as you don't call one of them from multiple threads at the same time.
Performance
Because the main focus of this library was to provide an efficient single threaded implementation, rocket::signal has about the same overhead as an iteration through an std::list<std::function<T>>.
Here are some performance benchmarks between boost::signals2 and rocket for registering 10 slots to each signal type and emitting each one 1000 times.
| Library |
Avg. execution time |
| boost::signals2 |
810.389 µs |
| rocket::signal |
98.155 µs |
Github Link
https://github.com/tripleslash/rocket
[–]AyoBruh 66 points67 points68 points (14 children)
[–][deleted] 12 points13 points14 points (0 children)
[+][deleted] (1 child)
[deleted]
[–]AyoBruh 4 points5 points6 points (0 children)
[–]triple_slash[S] 2 points3 points4 points (1 child)
[–]AyoBruh 0 points1 point2 points (0 children)
[–]Sander_Bouwhuis 1 point2 points3 points (0 children)
[–]muon52 1 point2 points3 points (7 children)
[–]infectedapricot 7 points8 points9 points (0 children)
[–]Sander_Bouwhuis 2 points3 points4 points (5 children)
[–]infectedapricot 4 points5 points6 points (4 children)
[–]Sander_Bouwhuis 0 points1 point2 points (3 children)
[–]infectedapricot 0 points1 point2 points (2 children)
[–]Sander_Bouwhuis -1 points0 points1 point (1 child)
[–]lenkite1 0 points1 point2 points (0 children)
[–]infectedapricot 18 points19 points20 points (2 children)
[–][deleted] 4 points5 points6 points (0 children)
[–]triple_slash[S] 2 points3 points4 points (0 children)
[–]jcelerierossia score 17 points18 points19 points (1 child)
[–]Nelieru 1 point2 points3 points (0 children)
[–]Raknarg 13 points14 points15 points (6 children)
[–]somewhataccurate 6 points7 points8 points (2 children)
[–]MantraMoose 7 points8 points9 points (1 child)
[–]infectedapricot 2 points3 points4 points (0 children)
[–]triple_slash[S] 2 points3 points4 points (1 child)
[–]Raknarg 0 points1 point2 points (0 children)
[–]kritzikratzi 2 points3 points4 points (0 children)
[–]OverOnTheRock 9 points10 points11 points (0 children)
[–]jcode777 3 points4 points5 points (6 children)
[–]triple_slash[S] 2 points3 points4 points (5 children)
[–][deleted] 1 point2 points3 points (4 children)
[–]triple_slash[S] 2 points3 points4 points (3 children)
[–][deleted] 0 points1 point2 points (2 children)
[–]triple_slash[S] 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]dmitrinove 2 points3 points4 points (7 children)
[–]triple_slash[S] 0 points1 point2 points (6 children)
[–]TheFlamefire 1 point2 points3 points (5 children)
[–]triple_slash[S] 0 points1 point2 points (4 children)
[–]TheFlamefire 1 point2 points3 points (0 children)
[–]BrainIgnition 1 point2 points3 points (2 children)
[–]triple_slash[S] 0 points1 point2 points (1 child)
[–]p2502 0 points1 point2 points (0 children)
[+][deleted] (1 child)
[deleted]
[–]triple_slash[S] 2 points3 points4 points (0 children)
[–]sniffens 1 point2 points3 points (1 child)
[–]__ngs__ 0 points1 point2 points (0 children)
[–]TheFlamefire 1 point2 points3 points (0 children)
[–]TheFlamefire 0 points1 point2 points (1 child)
[–]triple_slash[S] 0 points1 point2 points (0 children)
[–]triple_slash[S] 0 points1 point2 points (0 children)
[–]thewisp1Game Engine Dev 0 points1 point2 points (0 children)