|
UraniumCompute 0.1.0
A GPU accelerated parallel task scheduler
|
The reference counter that holds the number of references to the object. More...
#include <ReferenceCounter.h>
Public Member Functions | |
| ReferenceCounter (IAllocator *pAllocator) | |
| Create a new reference counter with specified allocator. More... | |
| UInt32 | AddStrongRef () |
| Add a strong reference to the counter. More... | |
| template<class F > | |
| UInt32 | ReleaseStrongRef (F &&destroyCallback) |
| Remove a strong reference from the counter. More... | |
| UInt32 | GetStrongRefCount () const |
| Get number of strong references. | |
The reference counter that holds the number of references to the object.
This class holds number of references to the object and a pointer to the allocator that was used to allocate this object. It assumes the following memory layout:
It will delete this assuming that a single block was used to allocate the object and the counter.
Example (pseudo-code):
This layout is used for better locality and performance: it groups two allocations into one. The internal reference counting system also supports copying shared pointers using their raw pointers:
|
inlineexplicit |
Create a new reference counter with specified allocator.
The specified allocator will be used to free memory after the counter reaches zero. This constructor initializes the counter to zero.
| pAllocator | - The allocator to use to free memory. |
|
inline |
Add a strong reference to the counter.
|
inline |
Remove a strong reference from the counter.
This function will delete the counter itself if number of references reaches zero.
| destroyCallback | - A function to invoke before deallocation if the counter reached zero. This is typically a lambda that calls object destructor. |
| F | - Type of callback function. |