ALib C++ Library
Library Version: 2402 R1
Documentation generated by doxygen
Loading...
Searching...
No Matches
alib::monomem Namespace Reference

Description:


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:

namespace  detail
 
namespace  util
 

Type Index:

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
 

Type Definition Index:

template<typename TKey , typename TMapped , typename THash = std::hash <TKey>, typename TEqual = std::equal_to<TKey>, lang::Caching THashCaching = lang::Caching::Auto, typename TRecycling = Recycling::Private>
using HashMap
 
template<typename T , typename THash = std::hash <T>, typename TEqual = std::equal_to<T>, lang::Caching THashCaching = lang::Caching::Auto, typename TRecycling = Recycling::Private>
using HashSet
 

Function Index:

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 ()
 

Variable Index:

ALIB_API uinteger DbgStatsStringTreeNameOverflows = 0
 
ALIB_API uinteger DbgStatsStringTreeNames = 0
 
MonoAllocator GlobalAllocator (8 *1024)
 
ALIB_API ThreadLock GlobalAllocatorLock
 

Type Definition Details:

◆ HashMap

template<typename TKey , typename TMapped , typename THash = std::hash <TKey>, typename TEqual = std::equal_to<TKey>, lang::Caching THashCaching = lang::Caching::Auto, typename TRecycling = Recycling::Private>
using HashMap
Initial value:
monomem::HashTable<std::pair<const TKey, TMapped>,
std::pair< TKey, TMapped>,
TKey, TMapped,
THash,
TEqual,
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 86 of file hashmap.hpp.

◆ HashSet

template<typename T , typename THash = std::hash <T>, typename TEqual = std::equal_to<T>, lang::Caching THashCaching = lang::Caching::Auto, typename TRecycling = Recycling::Private>
using HashSet
Initial value:
monomem::HashTable< T, T,
T, void,
THash,
TEqual,
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 76 of file hashset.hpp.

Function Details:

◆ AcquireGlobalAllocator()

MonoAllocator & 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()

template<typename THashtable >
AString 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 BaseCamp 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()

template<typename THashtable >
AString 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 BaseCamp 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()

template<typename THashtable >
std::tuple< double, double, integer, integer > 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()

template<typename T >
static ALIB_FORCE_INLINE void 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 651 of file monoallocator.hpp.

◆ ReleaseGlobalAllocator()

void ReleaseGlobalAllocator ( )
inline

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

Variable Details:

◆ DbgStatsStringTreeNameOverflows

ALIB_API uinteger DbgStatsStringTreeNameOverflows = 0

Statistic variable increased by StringTreeNamesDynamic with every creation of a node whose name exceeds the internal string buffer size. With process creation the variable is 0. A user may reset the variable to inspect percentages of name overflows during certain operations. The variable is not thread safe and used by any instance of class StringTree which uses node maintainer StringTreeNamesDynamic.

See also
Sibling variable DbgStatsStringTreeNameOverflows

Definition at line 92 of file monoallocator.cpp.

◆ DbgStatsStringTreeNames

ALIB_API uinteger DbgStatsStringTreeNames = 0

Statistic variable increased by StringTreeNamesDynamic with every creation of a node. With process creation the variable is 0. A user may reset the variable to inspect percentages of name overflows during certain operations. The variable is not thread safe and used by any instance of class StringTree which uses node maintainer StringTreeNamesDynamic.

See also
Sibling variable DbgStatsStringTreeNameOverflows

Definition at line 91 of file monoallocator.cpp.

◆ GlobalAllocator

ALIB_API MonoAllocator GlobalAllocator ( 8 * 1024)

This is the global monotonic allocator singleton instance.

See also

Definition at line 702 of file monoallocator.hpp.

◆ GlobalAllocatorLock

ALIB_API ThreadLock GlobalAllocatorLock
extern

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.