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 70 of file sharedmonoval.inl.
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 = std::conditional_t<std::same_as<void, TLock>, FieldMembersNoLock, FieldMembersWithLock> |
Protected Field Index: | |
FieldMembers * | members |
using alib::monomem::TSharedMonoVal< T, TAllocator, TLock >::AllocatorType = TMonoAllocator<TAllocator> |
Exposes the monotonic allocator used. Equals to TMonoAllocator<TAllocator>
.
Definition at line 174 of file sharedmonoval.inl.
|
protected |
The type of field members to include. Dependent on the template parameter TLock, either FieldMembersNoLock or FieldMembersWithLock is chosen.
Definition at line 163 of file sharedmonoval.inl.
using alib::monomem::TSharedMonoVal< T, TAllocator, TLock >::LockType = TLock |
Exposes the lock type specified with template parameter TLock.
Definition at line 180 of file sharedmonoval.inl.
using alib::monomem::TSharedMonoVal< T, TAllocator, TLock >::StoredType = T |
Exposes the stored type specified with template parameter T.
Definition at line 177 of file sharedmonoval.inl.
|
protected |
The object that is placed in the allocator's first buffer. Contains T, the allocator itself, and a reference counter.
Definition at line 167 of file sharedmonoval.inl.
|
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 197 of file sharedmonoval.inl.
|
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 227 of file sharedmonoval.inl.
|
inline |
Destructor. If this is the last copy, the destructors of T and of the MonoAllocator are invoked.
Definition at line 242 of file sharedmonoval.inl.
|
inlinenoexcept |
Default Constructor. Leaves this object nulled.
Definition at line 339 of file sharedmonoval.inl.
|
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 346 of file sharedmonoval.inl.
|
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 351 of file sharedmonoval.inl.
|
inlinenoexcept |
Move Constructor. Does not increase the reference counter, instead nulls the other.
other | The object to copy. |
Definition at line 357 of file sharedmonoval.inl.
|
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 296 of file sharedmonoval.inl.
|
inlinenoexcept |
Returns a constant reference to the stored object of type T.
Definition at line 448 of file sharedmonoval.inl.
|
inlinenoexcept |
Returns a non-constant pointer to the stored object of type T.
Definition at line 444 of file sharedmonoval.inl.
|
inlinenoexcept |
Definition at line 306 of file sharedmonoval.inl.
|
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 429 of file sharedmonoval.inl.
|
inlinenoexcept |
true
if this instance is not nulled, false
otherwise. Definition at line 451 of file sharedmonoval.inl.
|
inlinenoexcept |
Comparison with nullptr
.
false
if UseCount is greater than 0
. Definition at line 440 of file sharedmonoval.inl.
|
inlinenoexcept |
Overloaded operator to access members of custom type T
Definition at line 332 of file sharedmonoval.inl.
|
inlinenoexcept |
Overloaded operator to access members of custom type T
Definition at line 328 of file sharedmonoval.inl.
|
inlinenoexcept |
Overloaded operator to access members of custom type T
Definition at line 324 of file sharedmonoval.inl.
|
inlinenoexcept |
Overloaded operator to access members of custom type T
Definition at line 320 of file sharedmonoval.inl.
|
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 366 of file sharedmonoval.inl.
|
inline |
Assignment of nullptr
. Same as SetNulled.
Definition at line 432 of file sharedmonoval.inl.
|
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 390 of file sharedmonoval.inl.
|
inlinenoexcept |
Comparison with nullptr
.
true
if UseCount is greater than 0
. Definition at line 436 of file sharedmonoval.inl.
|
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 271 of file sharedmonoval.inl.
|
inlinenoexcept |
Returns a constant reference to the stored object of type T.
This can be used as an alias to (**this)
.
Definition at line 316 of file sharedmonoval.inl.
|
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 311 of file sharedmonoval.inl.
|
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 425 of file sharedmonoval.inl.
|
inlinestaticconstexpr |
Definition at line 301 of file sharedmonoval.inl.
|
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 419 of file sharedmonoval.inl.
|
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 414 of file sharedmonoval.inl.