This templated class is a utility type for TMonoAllocator and supports the following mechanics:
std::shared_ptr
is implemented with this type.nullptr
.All of the above results in the following:
nullptr
or invoking SetNulled.operator->()
. Alternatively (and sometimes needed) other provided operators and methods like Get may be used.In contrast to the container types SharedVal and SharedPtr, this type is most commonly used as a base class of types that should to be fully self-contained (like the types listed below).
T | The custom type that is embedded along with the MonoAllocator. |
TAllocator | The chained allocator that is used by the monotonous allocator that this type creates inside its first buffer. Usually, type HeapAllocator is to be given here. |
TLock | The type of ALib lock to embed besides T. With the provision of void , the integration of a lock is suppressed.See chapter 7.4 Locking Shared Values of the Programmer's Manual of module ALib Monomem for further details. |
Definition at line 86 of file sharedmonoval.hpp.
#include <sharedmonoval.hpp>
Inner Type Index: | |
struct | FieldMembersNoLock |
struct | FieldMembersWithLock |
Public Type Index: | |
using | AllocatorType = TMonoAllocator<TAllocator> |
Exposes the monotonic allocator used. Equals to TMonoAllocator<TAllocator> . | |
using | LockType = TLock |
Exposes the lock type specified with template parameter TLock. | |
using | StoredType = T |
Exposes the stored type specified with template parameter T. | |
Public Static Method Index: | |
static constexpr size_t | SizeOfAllocation () |
Public Method Index: | |
TSharedMonoVal () noexcept | |
Default Constructor. Leaves this object nulled. | |
TSharedMonoVal (const TSharedMonoVal &other) noexcept | |
TSharedMonoVal (size_t initialBufferSizeInKB, unsigned int bufferGrowthInPercent) | |
TSharedMonoVal (std::nullptr_t) noexcept | |
TSharedMonoVal (TAllocator &allocator, size_t initialBufferSizeInKB, unsigned int bufferGrowthInPercent) | |
TSharedMonoVal (TSharedMonoVal &&other) noexcept | |
~TSharedMonoVal () | |
void | Acquire (const CallerInfo &ci) const noexcept |
void | AcquireRecursive (const CallerInfo &ci) const noexcept |
void | AcquireShared (const CallerInfo &ci) const noexcept |
template<typename... TArgs> | |
void | ConstructT (TArgs &&... args) |
const T * | Get () const noexcept |
T * | Get () noexcept |
AllocatorType & | GetAllocator () noexcept |
TLock & | GetLock () const noexcept |
bool | IsNulled () const noexcept |
operator bool () const noexcept | |
bool | operator!= (std::nullptr_t) const noexcept |
const T & | operator* () const noexcept |
T & | operator* () noexcept |
const T * | operator-> () const noexcept |
T * | operator-> () noexcept |
TSharedMonoVal & | operator= (const TSharedMonoVal &other) noexcept |
void | operator= (std::nullptr_t) |
Assignment of nullptr . Same as SetNulled. | |
TSharedMonoVal & | operator= (TSharedMonoVal &&other) noexcept |
bool | operator== (std::nullptr_t) const noexcept |
void | Release (const CallerInfo &ci) const noexcept |
void | ReleaseRecursive (const CallerInfo &ci) const noexcept |
void | ReleaseShared (const CallerInfo &ci) const noexcept |
template<typename... TArgs> | |
void | Reset (TArgs &&... args) |
const T & | Self () const noexcept |
T & | Self () noexcept |
void | SetNulled () noexcept |
bool | TryAcquire (const CallerInfo &ci) const noexcept |
bool | TryAcquireShared (const CallerInfo &ci) const noexcept |
bool | TryAcquireSharedTimed (const Ticks &pointInTime, const CallerInfo &ci) const noexcept |
bool | TryAcquireSharedTimed (const Ticks::Duration &waitDuration, const CallerInfo &ci) const noexcept |
bool | TryAcquireSharedTimed (const Ticks::Duration::TDuration &waitDuration, const CallerInfo &ci) const noexcept |
bool | TryAcquireSharedTimed (const Ticks::TTimePoint &pointInTime, const CallerInfo &ci) const noexcept |
bool | TryAcquireTimed (const Ticks &pointInTime, const CallerInfo &ci) const noexcept |
bool | TryAcquireTimed (const Ticks::Duration &waitDuration, const CallerInfo &ci) const noexcept |
bool | TryAcquireTimed (const Ticks::Duration::TDuration &waitDuration, const CallerInfo &ci) const noexcept |
bool | TryAcquireTimed (const Ticks::TTimePoint &pointInTime, const CallerInfo &ci) const noexcept |
bool | Unique () const noexcept |
unsigned int | UseCount () const noexcept |
Protected Type Index: | |
using | FieldMembers = ATMP_IF_T_F(ATMP_EQ(void, TLock), FieldMembersNoLock, FieldMembersWithLock) |
Protected Field Index: | |
FieldMembers * | members |
using AllocatorType = TMonoAllocator<TAllocator> |
Exposes the monotonic allocator used. Equals to TMonoAllocator<TAllocator>
.
Definition at line 187 of file sharedmonoval.hpp.
|
protected |
The type of field members to include. Dependent on the template parameter TLock, either FieldMembersNoLock or FieldMembersWithLock is chosen.
Definition at line 176 of file sharedmonoval.hpp.
using LockType = TLock |
Exposes the lock type specified with template parameter TLock.
Definition at line 193 of file sharedmonoval.hpp.
using StoredType = T |
Exposes the stored type specified with template parameter T.
Definition at line 190 of file sharedmonoval.hpp.
|
protected |
The object that is placed in the allocator's first buffer. Contains T, the allocator itself, and a reference counter.
Definition at line 180 of file sharedmonoval.hpp.
|
inline |
Constructs an initial buffer of given size and creates the mono allocator within.
allocator | The (chained) allocator used to create the initial buffer and passed to the monotonous allocator that is created. |
initialBufferSizeInKB | The initial size of memory buffers used with the monotonic allocator in kB (1024 bytes) |
bufferGrowthInPercent | Optional growth factor in percent, applied to the buffer size with each next buffer allocation. Should be set to 200 , to double the size with each allocation. |
Definition at line 210 of file sharedmonoval.hpp.
|
inline |
Constructor missing the allocator instance. To be used only with allocators that are default constructible (like HeapAllocator is).
initialBufferSizeInKB | The initial size of memory buffers used with the monotonic allocator in kB (1024 bytes) |
bufferGrowthInPercent | Optional growth factor in percent, applied to the buffer size with each next buffer allocation. Should be set to 200 , to double the size with each allocation. |
Definition at line 238 of file sharedmonoval.hpp.
|
inline |
Destructor. If this is the last copy, the destructors of T and of the MonoAllocator are invoked.
Definition at line 251 of file sharedmonoval.hpp.
|
inlinenoexcept |
Default Constructor. Leaves this object nulled.
Definition at line 348 of file sharedmonoval.hpp.
|
inlinenoexcept |
Constructs an empty instance from std::nullptr
. This constructor is necessary to allow assignment of std::nullptr
to values of this type, which clears the automatic pointer.
std::nullptr
is possible. Definition at line 355 of file sharedmonoval.hpp.
|
inlinenoexcept |
Copy Constructor. Increases the reference counter of the shared pointer (in case given other is not nulled).
other | The object to copy. |
Definition at line 360 of file sharedmonoval.hpp.
|
inlinenoexcept |
Move Constructor. Does not increase the reference counter, instead nulls the other.
other | The object to copy. |
Definition at line 366 of file sharedmonoval.hpp.
|
inlinenoexcept |
Calls this Acquire on the embedded instance specified with template parameter TLock. This method participates in the overload resolution only if TLock provides an equivalent method.
ci | Caller information. Available only with debug-builds. |
|
noexcept |
Calls this Acquire on the embedded instance specified with template parameter TLock. This method participates in the overload resolution only if TLock provides an equivalent method.
ci | Caller information. Available only with debug-builds. |
|
noexcept |
Calls this Acquire on the embedded instance specified with template parameter TLock. This method participates in the overload resolution only if TLock provides an equivalent method.
ci | Caller information. Available only with debug-builds. |
|
inline |
Constructs the custom members. This method has to be called right after this instance was created with a non-nulled state.
Usually, this is done in the constructor of a dedicated derived type.
TArgs | The argument types used for constructing T. |
args | The arguments to construct the instance of T. |
Definition at line 305 of file sharedmonoval.hpp.
|
inlinenoexcept |
Returns a constant reference to the stored object of type T.
Definition at line 457 of file sharedmonoval.hpp.
|
inlinenoexcept |
Returns a non-constant pointer to the stored object of type T.
Definition at line 453 of file sharedmonoval.hpp.
|
inlinenoexcept |
Definition at line 315 of file sharedmonoval.hpp.
|
noexcept |
Returns the embedded TLock. This method is available only if the template parameter TLock is not equal to void
.
|
inlinenoexcept |
Returns true
if this is an empty instance.
true
if UseCount is 0
, false
otherwise. Definition at line 438 of file sharedmonoval.hpp.
|
inlinenoexcept |
true
if this instance is not nulled, false
otherwise. Definition at line 460 of file sharedmonoval.hpp.
|
inlinenoexcept |
Comparison with nullptr
.
false
if UseCount is greater than 0
. Definition at line 449 of file sharedmonoval.hpp.
|
inlinenoexcept |
Overloaded operator to access members of custom type T
Definition at line 341 of file sharedmonoval.hpp.
|
inlinenoexcept |
Overloaded operator to access members of custom type T
Definition at line 337 of file sharedmonoval.hpp.
|
inlinenoexcept |
Overloaded operator to access members of custom type T
Definition at line 333 of file sharedmonoval.hpp.
|
inlinenoexcept |
Overloaded operator to access members of custom type T
Definition at line 329 of file sharedmonoval.hpp.
|
inlinenoexcept |
Copy Assignment Operator. Cares for self-assignment and assignment of a shared pointer with the same content. Otherwise, the reference counter of the current object is decreased, disposed if necessary, and then the object in other is copied to this object.
other | The object to copy into this one. |
this
. Definition at line 375 of file sharedmonoval.hpp.
|
inline |
Assignment of nullptr
. Same as SetNulled.
Definition at line 441 of file sharedmonoval.hpp.
|
inlinenoexcept |
Move Assignment Operator. Cares for self-assignment. Otherwise, the object in other is copied to this.
other | The object to move into this one. |
this
. Definition at line 399 of file sharedmonoval.hpp.
|
inlinenoexcept |
Comparison with nullptr
.
true
if UseCount is greater than 0
. Definition at line 445 of file sharedmonoval.hpp.
|
noexcept |
Calls this Acquire on the embedded instance specified with template parameter TLock. This method participates in the overload resolution only if TLock provides an equivalent method.
ci | Caller information. Available only with debug-builds. |
|
noexcept |
Calls this Acquire on the embedded instance specified with template parameter TLock. This method participates in the overload resolution only if TLock provides an equivalent method.
ci | Caller information. Available only with debug-builds. |
|
noexcept |
Calls this Acquire on the embedded instance specified with template parameter TLock. This method participates in the overload resolution only if TLock provides an equivalent method.
ci | Caller information. Available only with debug-builds. |
|
inline |
Resets the monotonic allocator that this object is contained in to the snapshot created right after construction. The allocated memory buffers will remain allocated and reused. Before resetting, the destructor of the custom object T is invoked, and after the reset, in-place construction is performed.
All shared instances remain valid (while, of-course, their content is likewise reset).
It is up to the implementation of the derived class if this method should be exposed or not. It is also up to the implementation of the derived class if the internal allocator should be exposed for 3rd-party usage or not.
TArgs | The argument types used for re-constructing T. |
args | The arguments to re-construct the instance of T. |
Definition at line 280 of file sharedmonoval.hpp.
|
inlinenoexcept |
Returns a constant reference to the stored object of type T.
This can be used as an alias to (**this)
.
Definition at line 325 of file sharedmonoval.hpp.
|
inlinenoexcept |
Returns a non-constant reference to the stored object of type T.
This can be used as an alias to (**this)
.
Definition at line 320 of file sharedmonoval.hpp.
|
inlinenoexcept |
Sets this object to nulled state, as if default constructed or nullptr
was assigned. If no shared copy exists, all data is destructed and memory is freed.
As an alternative to this method, nullptr
can be assigned.
Definition at line 434 of file sharedmonoval.hpp.
|
inlinestaticconstexpr |
Definition at line 310 of file sharedmonoval.hpp.
|
nodiscardnoexcept |
Calls this Acquire on the embedded instance specified with template parameter TLock. This method participates in the overload resolution only if TLock provides an equivalent method.
ci | Caller information. Available only with debug-builds. |
true
if the lock was not acquired by a different thread and thus, this call was successful. false
otherwise.
|
nodiscardnoexcept |
Calls this Acquire on the embedded instance specified with template parameter TLock. This method participates in the overload resolution only if TLock provides an equivalent method.
ci | Caller information. Available only with debug-builds. |
true
if the lock was not acquired by a different thread and thus, this call was successful. false
otherwise.
|
nodiscardnoexcept |
Calls this TryAcquireSharedTimed on the embedded instance specified with template parameter TLock. This method participates in the overload resolution only if TLock provides an equivalent method.
pointInTime | The point in time, when this method stops waiting. |
ci | Caller information. Available only with debug-builds. |
true
if the lock was not acquired by a different thread and thus, this call was successful. false
otherwise.
|
nodiscardnoexcept |
Calls this TryAcquireSharedTimed on the embedded instance specified with template parameter TLock. This method participates in the overload resolution only if TLock provides an equivalent method.
waitDuration | The point in time, when this method stops waiting. |
ci | Caller information. Available only with debug-builds. |
true
if the lock was not acquired by a different thread and thus, this call was successful. false
otherwise.
|
nodiscardnoexcept |
Calls this TryAcquireSharedTimed on the embedded instance specified with template parameter TLock. This method participates in the overload resolution only if TLock provides an equivalent method.
waitDuration | The point in time, when this method stops waiting. |
ci | Caller information. Available only with debug-builds. |
true
if the lock was not acquired by a different thread and thus, this call was successful. false
otherwise.
|
nodiscardnoexcept |
Calls this TryAcquireSharedTimed on the embedded instance specified with template parameter TLock. This method participates in the overload resolution only if TLock provides an equivalent method.
pointInTime | The point in time, when this method stops waiting. |
ci | Caller information. Available only with debug-builds. |
true
if the lock was not acquired by a different thread and thus, this call was successful. false
otherwise.
|
noexcept |
Calls this TryAcquireTimed on the embedded instance specified with template parameter TLock. This method participates in the overload resolution only if TLock provides an equivalent method.
pointInTime | The point in time, when this method stops waiting. |
ci | Caller information. Available only with debug-builds. |
true
if the lock was not acquired by a different thread and thus, this call was successful. false
otherwise.
|
nodiscardnoexcept |
Calls this TryAcquireTimed on the embedded instance specified with template parameter TLock. This method participates in the overload resolution only if TLock provides an equivalent method.
waitDuration | The point in time, when this method stops waiting. |
ci | Caller information. Available only with debug-builds. |
true
if the lock was not acquired by a different thread and thus, this call was successful. false
otherwise.
|
nodiscardnoexcept |
Calls this TryAcquireTimed on the embedded instance specified with template parameter TLock. This method participates in the overload resolution only if TLock provides an equivalent method.
waitDuration | The point in time, when this method stops waiting. |
ci | Caller information. Available only with debug-builds. |
true
if the lock was not acquired by a different thread and thus, this call was successful. false
otherwise.
|
nodiscardnoexcept |
Calls this TryAcquireTimed on the embedded instance specified with template parameter TLock. This method participates in the overload resolution only if TLock provides an equivalent method.
pointInTime | The point in time, when this method stops waiting. |
ci | Caller information. Available only with debug-builds. |
true
if the lock was not acquired by a different thread and thus, this call was successful. false
otherwise.
|
inlinenoexcept |
Returns true
if the UseCount is 1
.
true
if this instance is set but not shared. Definition at line 428 of file sharedmonoval.hpp.
|
inlinenoexcept |
Returns the number of shared usages. In a multithreaded environment, the value returned is approximate.
The
number of shared usages. If this instance was default-constructed, moved, method SetNulled was called, or nullptr
was assigned, then 0
is returned. Definition at line 423 of file sharedmonoval.hpp.