PCL
|
Thread-safe reference counter for copy-on-write data structures. More...
#include <ReferenceCounter.h>
Inherited by pcl::GenericString< T, R, A >::Data, and pcl::RGBColorSystem::Data.
Public Member Functions | |
ReferenceCounter ()=default | |
ReferenceCounter (const ReferenceCounter &) | |
~ReferenceCounter () | |
void | Attach () |
bool | Detach () |
bool | IsUnique () const |
bool | IsUniqueAtomic () const |
ReferenceCounter & | operator= (const ReferenceCounter &)=delete |
int | RefCount () const |
int | RefCountAtomic () const |
ReferenceCounter is used internally by most PCL container and image classes to implement reference-counted, copy-on-write shared data.
ReferenceCounter is a thread-safe reference counter because it implements its internal counter as an instance of the AtomicInt class. This means that counter increment and decrement are implemented as atomic operations.
Copy-on-write is a fundamental technique for optimization of resources and execution speed by preventing unnecessary duplication of data, especially when objects are copied and aliased frequently but seldom modified. Basically, a set of objects can share the same data with the condition that the data remains unmodified. In this case, the set of objects is said to be referencing a single data item, and all objects in the set are considered as aliases of the data. When an alias object tries to modify its referenced data, a new copy is generated on-demand and the object uniquely references the newly generated data, which can then be freely modified. This mechanism works in a completely automatic and transparent way, and ReferenceCounter just provides a thread-safe counter to keep track of the number of aliased objects that reference the same data structure at a given time, plus a number of useful related functions.
Definition at line 99 of file ReferenceCounter.h.
|
default |
Constructs a new ReferenceCounter object. The reference counter is initialized to one, which means that only one object (the caller) is referencing the data associated with this object.
|
inline |
Destroys a ReferenceCounter object.
Definition at line 113 of file ReferenceCounter.h.
|
inline |
Copy constructor. This constructor is equivalent to the default constructor because reference counters are unique objects. In other words, the reference counter is always initialized to one for newly constructed ReferenceCounter objects.
This constructor exists and is not disabled to allow reference-counted data structures to have copy constructors.
Definition at line 126 of file ReferenceCounter.h.
|
inline |
Increments the reference counter by one unit. This happens when a new object references the data being controlled with this counter.
Definition at line 146 of file ReferenceCounter.h.
|
inline |
Decrements the reference counter by one unit. This happens when an object ceases to reference the data being controlled with this counter.
Returns true if the reference counter is greater than zero after the decrement; false if the reference counter becomes zero. When the reference counter is zero, the data being controlled with this counter is no longer referenced by any object and thus can be safely destroyed.
Definition at line 165 of file ReferenceCounter.h.
|
inline |
Returns true iff the data being controlled with this counter is not being referenced by more than one object.
Definition at line 200 of file ReferenceCounter.h.
|
inline |
Returns true iff the data being controlled with this counter is not being referenced by more than one object.
Definition at line 214 of file ReferenceCounter.h.
|
delete |
Copy assignment. This operator is disabled because reference counters are unique objects.
|
inline |
Returns the current value of this reference counter.
Definition at line 176 of file ReferenceCounter.h.
|
inline |
Returns the current value of this reference counter.
Definition at line 189 of file ReferenceCounter.h.