ALib C++ Library
Library Version: 2312 R0
Documentation generated by doxygen
Nested namespaces | Classes | Typedefs | Variables | Functions
aworx::lib::monomem Namespace Reference


This ALib Module implements the concept of "monotonic allocation" by providing central class MonoAllocator and a few corresponding container and utility types.

Please consult ALib Module Memory - Programmer's Manual for further information.

Nested namespaces

 detail
 
 util
 

Classes

class  HashTable
 
class  List
 
class  MonoAllocator
 
struct  Recycling
 
class  SelfContained
 
struct  StdContMA
 
struct  StdContMAOptional
 
struct  StdContMARecycling
 
class  StringTree
 
struct  StringTreeNamesDynamic
 
struct  StringTreeNamesMonoAlloc
 
struct  StringTreeNamesStatic
 
class  TMAString
 

Typedefs

template<typename TKey , typename TMapped , typename THash = std::hash <TKey>, typename TEqual = std::equal_to<TKey>, Caching THashCaching = Caching::Auto, typename TRecycling = Recycling::Private>
using HashMap = lib::monomem::HashTable< std::pair< const TKey, TMapped >, std::pair< TKey, TMapped >, TKey, TMapped, THash, TEqual, lib::monomem::detail::HashMapAccess< TKey, TMapped >, THashCaching, TRecycling >
 
template<typename T , typename THash = std::hash <T>, typename TEqual = std::equal_to<T>, Caching THashCaching = Caching::Auto, typename TRecycling = Recycling::Private>
using HashSet = lib::monomem::HashTable< T, T, T, void, THash, TEqual, lib::monomem::detail::HashSetAccess< T >, THashCaching, TRecycling >
 

Variables

MonoAllocator GlobalAllocator (8 *1024)
 
ALIB_API ThreadLock GlobalAllocatorLock
 

Functions

MonoAllocatorAcquireGlobalAllocator (const NCString &dbgFile, int dbgLine, const NCString &dbgFunc)
 
template<typename THashtable >
AString DbgDumpDistribution (const THashtable &hashtable, bool detailedBucketList)
 
template<typename THashtable >
AString DbgDumpHashtable (const THashtable &hashtable)
 
template<typename THashtable >
std::tuple< double, double, integer, integerDbgGetHashTableDistribution (const THashtable &hashtable)
 
template<typename T >
static ALIB_FORCE_INLINE void Destruct (T *object)
 
void ReleaseGlobalAllocator ()
 

Typedef Documentation

◆ HashMap

using HashMap = lib::monomem::HashTable<std::pair<const TKey, TMapped>, std::pair< TKey, TMapped>, TKey, TMapped, THash, TEqual, lib::monomem::detail::HashMapAccess<TKey, TMapped>, THashCaching, TRecycling >

This type definition is a shortcut to HashTable, usable if the data stored in the container consists of two parts, a key and a mapped part, where only the key-part is to be used for the comparison of values.

See also
For a detailed description of this type, see original type HashTable.
Another type definition based on HashTable is provided with HashSet.
Template Parameters
TKeyThe type of the key-portion of the inserted data.
This type is published as HashTable::KeyType.
TMappedThe type of the mapped-portion of the inserted data.
This type is published as HashTable::MappedType.
THashThe hash functor applicable to TKey.
Defaults to std::hash<TKey> and is published as HashTable::HashType.
TEqualThe comparison functor on TKey.
Defaults to std::equal_to<TKey> and is published as HashTable::EqualType.
THashCachingDetermines if hash codes are cached when elements are inserted.
Defaults to Caching::Auto, which enables caching if std::is_arithmetic<TKey>::value evaluates to false.
TRecyclingDenotes the type of recycling that is to be performed. Possible values are Recycling::Private (the default), Recycling::Shared or Recycling::None.

Definition at line 95 of file hashmap.hpp.

◆ HashSet

using HashSet = lib::monomem::HashTable< T, T, T, void, THash, TEqual, lib::monomem::detail::HashSetAccess<T>, THashCaching, TRecycling >

This type definition is a shortcut to HashTable, usable if the full portion of the data stored in the container is used for the comparison of values.

Note
As with this definition template type TKey equals inserted type T, methods of target type HashTable that accept an object of template type TKey expect an object of T when this type is used.
See also
For a detailed description of this type, see original type HashTable.
Another type definition based on HashTable is provided with HashMap.
Template Parameters
TThe element type stored with this container. This type is published as HashTable::ValueType and type definition HashTable::KeyType becomes a synonym.
THashThe hash functor applicable to TKey.
Defaults to std::hash<TKey> and is published as HashTable::HashType.
TEqualThe comparison functor on TKey.
Defaults to std::equal_to<TKey> and is published as HashTable::EqualType.
THashCachingDetermines if hash codes are cached when elements are inserted.
Defaults to Caching::Auto, which enables caching if std::is_arithmetic<T>::value evaluates to false.
TRecyclingDenotes the type of recycling that is to be performed. Possible values are Recycling::Private (the default), Recycling::Shared or Recycling::None.

Definition at line 82 of file hashset.hpp.

Function Documentation

◆ AcquireGlobalAllocator()

MonoAllocator& aworx::lib::monomem::AcquireGlobalAllocator ( const NCString dbgFile,
int  dbgLine,
const NCString dbgFunc 
)
inline

Simple inline function that acquires GlobalAllocatorLock and returns the object singleton GlobalAllocator.

See also
Namespace function ReleaseGlobalAllocator.
Parameters
dbgFileCaller information. Available only with debug builds and if ALib Threads is included in the ALib Distribution.
dbgLineCaller information. Available only with debug builds and if ALib Threads is included in the ALib Distribution.
dbgFuncCaller information. Available only with debug builds and if ALib Threads is included in the ALib Distribution.
Returns
A reference to the global monotonic allocator instance AcquireGlobalAllocator.

◆ DbgDumpDistribution()

AString aworx::lib::monomem::DbgDumpDistribution ( const THashtable &  hashtable,
bool  detailedBucketList 
)
inline

Invokes method DbgGetHashTableDistribution and creates human readable output, ready to be logged or written to the console.

Availability

Available only if compiler symbol ALIB_DEBUG_MONOMEM is set and module ALib Text is included in the alibdist.

See also
Sibling namespace functions DbgGetHashTableDistribution and DbgDumpHashtable provided for debugging and optimization.
Template Parameters
THashtableA specification of templated type HashTable. Deduced by the compiler by given parameter hashtable.
Parameters
hashtableThe hashtable to investigate on.
detailedBucketListIf true is given, for each bucket a line with its size value and a "size bar" is written.
Returns
A string containing human readable information about the distribution of elements in the hashtable.

Definition at line 2460 of file hashtable.hpp.

Here is the call graph for this function:

◆ DbgDumpHashtable()

AString aworx::lib::monomem::DbgDumpHashtable ( const THashtable &  hashtable)
inline

Dumps all values of the hash table sorted by buckets. Besides other scenarios of usage, this method allows to investigate into how the keys of the table are distributed in the buckets, and thus learn something about the hash algorithm used.

Prior to invoking this method, specializations of T_Append have to be made and furthermore, boxed values of the type have to be "made appendable" to instances of type AString. The latter is rather simple, if done using this macro during bootstrap.

Note
If the prerequisites for using this method seem to be too complicated and not worth the effort for a "quick debug session", it is recommended to just copy the source code of this inline function and adopt the Formatter::Format statement to suit a specific type stored in hashtable.

Availability

Available only if compiler symbol ALIB_DEBUG_MONOMEM is set and module ALib Text is included in the alibdist.

See also
Sibling namespace functions DbgGetHashTableDistribution and DbgDumpDistribution provided for debugging and optimization.
Template Parameters
THashtableA specification of templated type HashTable. Deduced by the compiler by given parameter hashtable.
Parameters
hashtableThe hashtable to investigate on.
Returns
A string containing a dump of the given hash table's contents.

Definition at line 2548 of file hashtable.hpp.

Here is the call graph for this function:

◆ DbgGetHashTableDistribution()

std::tuple<double,double,integer,integer> aworx::lib::monomem::DbgGetHashTableDistribution ( const THashtable &  hashtable)
inline

Generates statistics on the given hash table. The meanings of the returned tuple are: 0. The expected average size of a bucket (simply table size divided by number of buckets).

  1. The standard deviation of the buckets. The lower this value, the better is the hash algorithm used. A value of 1.0 denotes the gaussian distribution which indicates perfect randomness. However, this value is unlikely (impossible) to be achieved.
  2. The minimum number of elements found in a bucket.
  3. The maximum number of elements found in a bucket.

Availability

Available only if compiler symbol ALIB_DEBUG_MONOMEM is set.

See also
Sibling namespace functions DbgDumpDistribution and DbgDumpHashtable provided for debugging and optimization.
Template Parameters
THashtableA specification of templated type HashTable. Deduced by the compiler by given parameter hashtable.
Parameters
hashtableThe hashtable to investigate on.
Returns
The tuple as described above.

Definition at line 2403 of file hashtable.hpp.

◆ Destruct()

static ALIB_FORCE_INLINE void aworx::lib::monomem::Destruct ( T *  object)
static

This static inline namespace function calls the destructor ~T()of given object. The use of this method is recommended instead of calling the destructor directly, to increase readability of the code.

Template Parameters
TThe object type. Deduced by the compiler and not needed to be given.
Parameters
objectThe object to destruct.

Definition at line 659 of file monoallocator.hpp.

◆ ReleaseGlobalAllocator()

void aworx::lib::monomem::ReleaseGlobalAllocator ( )
inline

Simple inline function that releases GlobalAllocatorLock, previously acquired with AcquireGlobalAllocator.

Variable Documentation

◆ GlobalAllocator

ALIB_API MonoAllocator GlobalAllocator

This is the global monotonic allocator singleton instance.

See also

Definition at line 710 of file monoallocator.hpp.

◆ GlobalAllocatorLock

ALIB_API ThreadLock GlobalAllocatorLock

This mutex is used by methods AcquireGlobalAllocator and ReleaseGlobalAllocator to control access over the global allocator instance GlobalAllocator.

This object may be controlled directly as an alternative to using the functions named above, for example in combination with macro ALIB_LOCK_WITH, with attaches the locking/unlocking mechanisms "automatically" to the current call stack.