This templated class is a utility type for TMonoAllocator and supports the following mechanics:
MonoAllocator.MonoAllocator that receives this first buffer is likewise placed in the buffer.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 71 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 bufferGrowthInPercent) | |
| TSharedMonoVal (std::nullptr_t) noexcept | |
| TSharedMonoVal (TAllocator &allocator, size_t initialBufferSizeInKB, unsigned 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 | 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 168 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 157 of file sharedmonoval.hpp.
| using alib::monomem::TSharedMonoVal< T, TAllocator, TLock >::LockType = TLock |
Exposes the lock type specified with template parameter TLock.
Definition at line 174 of file sharedmonoval.hpp.
| using alib::monomem::TSharedMonoVal< T, TAllocator, TLock >::StoredType = T |
Exposes the stored type specified with template parameter T.
Definition at line 171 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 161 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 191 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 220 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 234 of file sharedmonoval.hpp.
|
inlinenoexcept |
Default Constructor. Leaves this object nulled.
Definition at line 327 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 334 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 339 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 345 of file sharedmonoval.hpp.
|
inlinenoexcept |
Calls 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 AcquireRecursive 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 AcquireShared 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 284 of file sharedmonoval.hpp.
|
inlinenoexcept |
Returns a constant reference to the stored object of type T.
Definition at line 431 of file sharedmonoval.hpp.
|
inlinenoexcept |
Returns a non-constant pointer to the stored object of type T.
Definition at line 427 of file sharedmonoval.hpp.
|
inlinenoexcept |
Definition at line 294 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 412 of file sharedmonoval.hpp.
|
inlinenoexcept |
true if this instance is not nulled, false otherwise. Definition at line 434 of file sharedmonoval.hpp.
|
inlinenoexcept |
Comparison with nullptr.
false if UseCount is greater than 0. Definition at line 423 of file sharedmonoval.hpp.
|
inlinenoexcept |
Overloaded operator to access members of the custom type T
Definition at line 320 of file sharedmonoval.hpp.
|
inlinenoexcept |
Overloaded operator to access members of the custom type T
Definition at line 316 of file sharedmonoval.hpp.
|
inlinenoexcept |
Overloaded operator to access members of custom type T
Definition at line 312 of file sharedmonoval.hpp.
|
inlinenoexcept |
Overloaded operator to access members of custom type T
Definition at line 308 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 354 of file sharedmonoval.hpp.
|
inline |
Assignment of nullptr. Same as SetNulled.
Definition at line 415 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 376 of file sharedmonoval.hpp.
|
inlinenoexcept |
Comparison with nullptr.
true if UseCount is greater than 0. Definition at line 419 of file sharedmonoval.hpp.
|
noexcept |
Calls Release 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 ReleaseRecursive 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 ReleaseShared 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 260 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 304 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 299 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 408 of file sharedmonoval.hpp.
|
inlinestaticconstexpr |
Definition at line 289 of file sharedmonoval.hpp.
|
nodiscardnoexcept |
Calls TryAcquire 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 TryAcquireShared 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 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 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 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 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 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 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 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 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 403 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 398 of file sharedmonoval.hpp.