Thrill
0.1
|
CountingPtr is an implementation of intrusive reference counting. This is similar, but not identical to boost or C++ TR1's shared_ptr
. Intrusive reference counting requires the counted class to contain the counter, which is not required by std::shared_ptr
.
Intrusive counting is often faster due to fewer cache faults. Furthermore, CountingPtr is a single pointer, whereas std::shared_ptr
actually contains (at least) two pointers. CountingPtr also creates a lot less debug info due to reduced complexity.
CountingPtr is accompanied by ReferenceCounter, which contains the actual reference counter (a single integer). A reference counted object must derive from ReferenceCounter :
Code that now wishes to use pointers referencing this object, will typedef an CountingPtr, which is used to increment and decrement the included reference counter automatically.
The CountingPtr can generally be used like a usual pointer or std::shared_ptr
(see the docs for more).