ALib C++ Library
Library Version: 2412 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
TMonoAllocator< TAllocator > Class Template Reference

Description:

template<typename TAllocator>
class alib::monomem::TMonoAllocator< TAllocator >
Important Note
Please consult the Programmer's Manual of ALib module ALib Monomem for an introduction into the rather complex topic of monotonous allocation and how to use this class.
General Behavior
Implements a monotonic allocator. Allocates a series of bigger memory buffers and offers sequential allocation of portions of those.
With construction, an initial memory buffer is received from the chained allocator. The size of this buffer is defined with the constructor parameter initialBufferSizeInKB. With each necessary allocation of a next buffer, this value can be increased, according to the optional parameter bufferGrowthInPercent, which defaults to 200, resulting in doubling the size of each next buffer.

If an invocation of one of the allocation methods requests memory bigger than the remaining space in the actual (last) buffer, then a new buffer is created and made the actual buffer. The remaining space of the former actual buffer will not be used for future allocations and is wasted in this respect.

Oversized Allocations
If a requested allocation size exceeds what would be the size of the next buffer, then a new buffer of the extended size is created. The next allocation will then create a new buffer which continues the originally defined buffer growth path. In other words:
  • Oversized allocations are allowed, and
  • the next buffer's size after an oversized allocation will use the size of the last non-oversized buffer as the base value for calculating the next size.
Note
While accepted, oversized allocations should still be avoided, because the current buffer will not be used for further allocations. This is a design decision, allowing a more efficient implementation of this class. Former implementations kept the current buffer as the actual buffer, when an oversized allocation occured, but this feature was dropped.
Resetting
The allocator can be reset to a certain state (see TakeSnapshot and Reset), which disposes all memory behind the snapshot. Disposed complete buffers will not be freed, but "recycled" with future allocations.
If nested snapshots are used in the right places, further gains in execution performance can be achieved.
External Allocation of the First Buffer
Special constructors of this type allow to pass an existing first buffer for usage. This allows two fundamental concepts:
  • The first buffer might be stack-memory, which can lead to further (sometimes dramatical) performance improvements.
    This feature is leveraged by type TLocalAllocator.
  • The first buffer might contain not only already emplaced objects, but even the TMonoAllocator itself. We name this a "self-contained monotonic allocator".
    This feature is leveraged by type TSharedMonoVal.
Debug Features
Depending on the compiler symbol ALIB_DEBUG_MONOMEM, some metrics on instances of this class become available. Those might for example be helpful to find a reasonable value for constructor parameters initialBufferSize and bufferGrowthInPercent.
See also
Template Parameters
TAllocatorThe underlying allocator to use.
With type definition MonoAllocator, this is bound to type HeapAllocator.
For general information see chapter 8. Allocator Chaining of the Programmer's Manual.

Definition at line 338 of file monoallocator.hpp.

#include <monoallocator.hpp>

Inheritance diagram for TMonoAllocator< TAllocator >:
[legend]
Collaboration diagram for TMonoAllocator< TAllocator >:
[legend]

Public Type Index:

using ChainedAllocator = TAllocator
 
- Public Type Index: inherited from AllocatorMember< TAllocator >
using AllocatorType = TAllocator
 Exposes the allocator type.
 

Public Static Field Index:

static constexpr size_t MAX_ALIGNMENT = (std::numeric_limits<size_t>::max)()
 
static constexpr size_t MIN_ALIGNMENT = 1
 

Public Field Index:

lang::Placeholder< lang::DbgCriticalSectionsDbgCriticalSectionsPH
 
const char * DbgName
 

Public Method Index:

 TMonoAllocator (const char *dbgName, detail::Buffer *pInitialBuffer, size_t pInitialBufferSizeInKB, unsigned int pBufferGrowthInPercent=200)
 
 TMonoAllocator (const char *dbgName, size_t pInitialBufferSizeInKB, unsigned int pBufferGrowthInPercent=200)
 
 TMonoAllocator (const char *dbgName, std::nullptr_t) noexcept
 
 TMonoAllocator (const char *dbgName, TAllocator &pAllocator, detail::Buffer *pInitialBuffer, size_t pInitialBufferSizeInKB, unsigned int pBufferGrowthInPercent=200)
 
ALIB_API TMonoAllocator (const char *dbgName, TAllocator &pAllocator, size_t pInitialBufferSizeInKB, unsigned int pBufferGrowthInPercent=200)
 
 TMonoAllocator (const TMonoAllocator &)=delete
 Not copyable.
 
 TMonoAllocator (TMonoAllocator &&)=delete
 Not movable.
 
ALIB_API ~TMonoAllocator ()
 Destructor. Disposes all memory allocated with ChainedAllocator.
 
lang::Allocator Implementation
void * allocate (size_t size, size_t alignment)
 
void * reallocate (void *mem, size_t oldSize, size_t newSize, size_t alignment)
 
void free (void *mem, size_t size) const
 
template<typename TSize >
void dbgAcknowledgeIncreasedAllocSize (void *, TSize) const
 
lang::AllocatorInterface< TMonoAllocatoroperator() ()
 
constexpr bool allowsMemSplit () noexcept
 
Snapshots and Reset
Snapshot TakeSnapshot ()
 
ALIB_API void Reset (Snapshot snapshot=Snapshot())
 
void Reset (size_t firstObjectSize, size_t firstObjectAlignment)
 
Statistics and Debug-Interface
ALIB_API void GetStatistics (Statistics &result)
 
ALIB_FORCE_INLINE void DbgLock (bool onOff) noexcept
 
template<typename TSize >
void dbgCheckMemory (void *mem, TSize size)
 
const DbgStatisticsDbgGetStatistics () const
 
ALIB_API NAString DbgDumpStatistics ()
 
- Public Method Index: inherited from AllocatorMember< TAllocator >
 AllocatorMember ()=delete
 Deleted default constructor. (The allocator has to be given with construction)
 
 AllocatorMember (TAllocator &pAllocator) noexcept
 
AllocatorInterface< TAllocator > AI () const noexcept
 
TAllocator & GetAllocator () const noexcept
 

Protected Type Index:

using allocMember = lang::AllocatorMember<TAllocator>
 The allocator type that TAllocator specifies.
 

Protected Field Index:

detail::Bufferbuffer
 The actual buffer. Contains a link to previously allocated buffers.
 
unsigned int bufferGrowthInPercent
 
bool dbgLock = false
 
DbgStatistics dbgStats
 
size_t nextBuffersUsableSize
 
detail::Bufferrecyclables
 The list of buffers that are to be recycled.
 
- Protected Field Index: inherited from AllocatorMember< TAllocator >
TAllocator & allocator
 A reference to the allocator.
 

Protected Method Index:

ALIB_API char * nextBuffer (size_t size, size_t alignment)
 

Type Definition Details:

◆ allocMember

template<typename TAllocator >
using allocMember = lang::AllocatorMember<TAllocator>
protected

The allocator type that TAllocator specifies.

Definition at line 342 of file monoallocator.hpp.

◆ ChainedAllocator

template<typename TAllocator >
using ChainedAllocator = TAllocator

The type of the allocator that this allocator uses underneath to allocate the buffers, given with template parameter TAllocator.
The instance can be accessed with inherited methods GetAllocator and AI.

Definition at line 409 of file monoallocator.hpp.

Field Details:

◆ buffer

template<typename TAllocator >
detail::Buffer* buffer
protected

The actual buffer. Contains a link to previously allocated buffers.

Definition at line 345 of file monoallocator.hpp.

◆ bufferGrowthInPercent

template<typename TAllocator >
unsigned int bufferGrowthInPercent
protected

Growth factor of subsequently allocated buffers. Given by a construction parameter, which in most cases defaults to 200, doubling the buffer size with each next buffer allocation.

Definition at line 358 of file monoallocator.hpp.

◆ DbgCriticalSectionsPH

template<typename TAllocator >
lang::Placeholder<lang::DbgCriticalSections> DbgCriticalSectionsPH

Due to the possibility of beeing self-contained, this type needs special treatment in respect to instance DbgCriticalSections. It must be neither derived nor being a member. Instead, destruction has to be controlled. Furthermore, the ALib Module Threads Macros cannot be used.

Definition at line 386 of file monoallocator.hpp.

◆ dbgLock

template<typename TAllocator >
bool dbgLock = false
protected

This flag to mark this allocator to not accept allocations.

See also
Method DbgLock and chapter 11.4 Debugging of the Programmer's Manual of this ALib Module.

Definition at line 370 of file monoallocator.hpp.

◆ DbgName

template<typename TAllocator >
const char* DbgName

A name for this object. With debug-compilations, this name has to be given with construction.

Definition at line 364 of file monoallocator.hpp.

◆ dbgStats

template<typename TAllocator >
DbgStatistics dbgStats
protected

Debug statistics measured on the whole run-time of this object.
Availability depends on code selector symbol ALIB_DEBUG_MONOMEM.

Definition at line 376 of file monoallocator.hpp.

◆ MAX_ALIGNMENT

template<typename TAllocator >
size_t MAX_ALIGNMENT = (std::numeric_limits<size_t>::max)()
staticconstexpr

Evaluates to std::numeric_limits<size_t>::max().

See also
Field Allocator::MAX_ALIGNMENT.

Definition at line 417 of file monoallocator.hpp.

◆ MIN_ALIGNMENT

template<typename TAllocator >
size_t MIN_ALIGNMENT = 1
staticconstexpr

Evaluates to 1.

See also
Field Allocator::MIN_ALIGNMENT.

Definition at line 413 of file monoallocator.hpp.

◆ nextBuffersUsableSize

template<typename TAllocator >
size_t nextBuffersUsableSize
protected

The initial allocation size given in the constructor, multiplied with bufferGrowthInPercent with each new buffer created. Allocated buffers may be bigger in the case that a single allocation is larger than this value.

Definition at line 353 of file monoallocator.hpp.

◆ recyclables

template<typename TAllocator >
detail::Buffer* recyclables
protected

The list of buffers that are to be recycled.

Definition at line 348 of file monoallocator.hpp.

Constructor(s) / Destructor Details:

◆ TMonoAllocator() [1/5]

template<typename TAllocator >
TMonoAllocator ( const char * dbgName,
std::nullptr_t  )
noexcept

Special constructor that is not initializing this type. This can be used if a value of this type is required, but only later it becomes known what the initial buffer size and growth factor is to be.

Method IsInitialized can be used to determine if an allocator was initialized on construction. If not, a placement-new calling a decent constructor is to be performed before construction.

Parameters
dbgNameHas to be specified with debug-compilations only. Use macro ALIB_DBG to pass a constant.
See also
Chapter 10.3 Changing the Default Size of the Programmer's Manual of module ALib Monomem.

◆ TMonoAllocator() [2/5]

template<typename TAllocator >
TMonoAllocator ( const char * dbgName,
detail::Buffer * pInitialBuffer,
size_t pInitialBufferSizeInKB,
unsigned int pBufferGrowthInPercent = 200 )

Constructor that accepts an external first buffer. If this constructor is used, and the given initialBuffer must not be freed to the heap, method destructWithExternalBuffer has to be called right before the allocator is destructed.

Note
This constructor, together with method destructWithExternalBuffer enables the efficient implementation of derived class TLocalAllocator, as well as class TSharedMonoVal.
Parameters
dbgNameHas to be specified with debug-compilations only. Use macro ALIB_DBG to pass a constant.
pInitialBufferThe initial buffer to use. Has to be aligned with at least alignof(void*).
pInitialBufferSizeInKBThe size in kB (1024 bytes) of the given initialBuffer.
pBufferGrowthInPercentOptional growth factor in percent, applied to each allocation of a next buffer size in respect to its previous size. Defaults to 200, which doubles buffer size with each next internal buffer allocation.

◆ TMonoAllocator() [3/5]

template<typename TAllocator >
TMonoAllocator ( const char * dbgName,
TAllocator & pAllocator,
detail::Buffer * pInitialBuffer,
size_t pInitialBufferSizeInKB,
unsigned int pBufferGrowthInPercent = 200 )

Alternative constructor version that in addition expects an allocator.

Parameters
dbgNameHas to be specified with debug-compilations only. Use macro ALIB_DBG to pass a constant.
pAllocatorThe allocator to use for allocation of buffers.
pInitialBufferThe initial buffer to use. Has to be aligned with at least alignof(void*).
pInitialBufferSizeInKBThe size in kB (1024 bytes) of the given initialBuffer.
pBufferGrowthInPercentOptional growth factor in percent, applied to each allocation of a next buffer size in respect to its previous size. Defaults to 200, which doubles buffer size with each next internal buffer allocation.

◆ TMonoAllocator() [4/5]

template<typename TAllocator >
TMonoAllocator ( const char * dbgName,
size_t pInitialBufferSizeInKB,
unsigned int pBufferGrowthInPercent = 200 )

Constructor. A first memory buffer is allocated from ChainedAllocator.

Parameter bufferGrowthInPercent determines the growth of memory buffers. The size of a next buffer is calculated as: newSize= (previousSize * bufferGrowthInPercent) / 100

Parameters
dbgNameHas to be specified with debug-compilations only. Use macro ALIB_DBG to pass a constant.
pInitialBufferSizeInKBThe size in kB (1024 bytes) of the first memory buffer used for the allocator itself as well as for the first allocations.
pBufferGrowthInPercentOptional growth factor in percent, applied to each allocation of a next buffer size in respect to its previous size. Defaults to 200, which doubles the buffer size with each next internal buffer allocation.

◆ TMonoAllocator() [5/5]

template<typename TAllocator >
ALIB_API TMonoAllocator ( const char * dbgName,
TAllocator & pAllocator,
size_t pInitialBufferSizeInKB,
unsigned int pBufferGrowthInPercent = 200 )

Alternative constructor accepting an allocator instance. To be used if template parameter TAllocator does not equal HeapAllocator or any (custom) default-constructible allocator type.

Parameters
dbgNameHas to be specified with debug-compilations only. Use macro ALIB_DBG to pass a constant.
pAllocatorThe allocator to use for allocation of buffers.
pInitialBufferSizeInKBThe size in kB (1024 bytes) of the first memory buffer used for the allocator itself as well as for the first allocations.
pBufferGrowthInPercentOptional growth factor in percent, applied to each allocation of a next buffer size in respect to its previous size. Defaults to 200, which doubles the buffer size with each next internal buffer allocation.

◆ ~TMonoAllocator()

template<typename TAllocator >
~TMonoAllocator ( )

Destructor. Disposes all memory allocated with ChainedAllocator.

Definition at line 59 of file monoallocator.t.hpp.

Method Details:

◆ allocate()

template<typename TAllocator >
void * allocate ( size_t size,
size_t alignment )
inline

Allocate memory from the internal buffer. If the buffer's size is exceeded, a next buffer is allocated and used.

Parameters
sizeThe size of memory the block to allocate in bytes. With this allocator this is not an input/output parameter.
alignmentThe (minimum) alignment of the memory block to allocate in bytes. See Chapter 11.1 Alignment of the Programmer's Manual of this module.
Returns
Pointer to the allocated memory.

Definition at line 756 of file monoallocator.hpp.

Here is the call graph for this function:

◆ allowsMemSplit()

template<typename TAllocator >
bool allowsMemSplit ( )
constexprnoexcept

See the description of this method with prototype Allocator::allowsMemSplit.
(Note: This method is static. For technical reasons this cannot be reflected in this documentation)

Returns
true, except if compiler symbol ALIB_DEBUG_ALLOCATIONS is given.

◆ Create() [1/2]

template<typename TAllocator >
static TMonoAllocator * Create ( const char * dbgName,
size_t initialBufferSizeInKB,
unsigned int bufferGrowthInPercent = 200 )
inlinestatic

Same as Create(const char*, TAllocator&, size_t, unsigned int), but misses the allocator parameter. Used with chained allocators that are default-constructible (e.g., HeapAllocator):

Parameters
dbgNameHas to be specified with debug-compilations only. Use macro ALIB_DBG to pass a constant.
initialBufferSizeInKBThe size of memory the buffers allocated in kilobytes.
bufferGrowthInPercentOptional growth factor in percent, applied to the buffer size with each next buffer allocation. Values provided should be greater than 100.
Defaults to 200, which doubles buffer size with each next internal buffer allocation.
Returns
A pointer to an instance of this type MonoAllocator residing in its first created buffer.

Definition at line 695 of file monoallocator.hpp.

Here is the call graph for this function:

◆ Create() [2/2]

template<typename TAllocator >
static ALIB_API TMonoAllocator * Create ( const char * dbgName,
TAllocator & pAllocator,
size_t initialBufferSizeInKB,
unsigned int bufferGrowthInPercent = 200 )
static

This static method creates an object of this type inside "itself", aka inside its first allocated buffer. Instances created with this method have to be deleted by only invoking the destructor, e.g., using Destruct.

Method Reset must not be called using its default parameter when an instance of this type was created by this method. Instead, if reset operations are desired, a snapshot has to be taken (see method TakeSnapshot) right after the invocation of this method and maybe other initial members that should survive a reset, which then has to be passed to method Reset.
Alternatively, if only the monotonic allocator should survive the reset, overloaded method Reset(size_t, size_t) might be used, passing sizeof(TMonoAllocator<T>) and alignof(TMonoAllocator<T>) as parameters.

Parameters
dbgNameHas to be specified with debug-compilations only. Use macro ALIB_DBG to pass a constant.
pAllocatorThe allocator used for creating the first buffer.
initialBufferSizeInKBThe size of memory the buffers allocated in kilobytes.
bufferGrowthInPercentOptional growth factor in percent, applied to the buffer size with each next buffer allocation. Values provided should be greater than 100.
Defaults to 200, which doubles buffer size with each next internal buffer allocation.
Returns
A pointer to an instance of this type MonoAllocator residing in its first created buffer.

◆ dbgAcknowledgeIncreasedAllocSize()

template<typename TAllocator >
template<typename TSize >
void dbgAcknowledgeIncreasedAllocSize ( void * ,
TSize  ) const
inline

This is an empty implementation of the prototyped method. It is empty because this allocator never returns a higher allocation size than requested. Allocator::dbgAcknowledgeIncreasedAllocSize.

Template Parameters
TSizeThe type of parameter allocSize. (Deduced by the compiler.)

Definition at line 863 of file monoallocator.hpp.

◆ dbgCheckMemory()

template<typename TAllocator >
template<typename TSize >
void dbgCheckMemory ( void * mem,
TSize size )
inline

If the compiler symbol ALIB_DEBUG_ALLOCATIONS is not set, this method is empty and will be optimized out. Otherwise, this will raise an ALib assertion if the piece of allocated memory is corrupted or its allocation size is not rightfully given by the using code.

See also
Chapter 11.4 Debugging of the Programmer's Manual.
Template Parameters
TSizeThe type of parameter size. (Deduced by the compiler.)
Parameters
memThe address of the allocated object.
sizeThe requested allocation size of the object.

Definition at line 979 of file monoallocator.hpp.

Here is the call graph for this function:

◆ DbgDumpStatistics()

template<typename TAllocator >
NAString DbgDumpStatistics ( )

Provides allocation statistics for manual performance optimization.

Availability
This method is included only in debug-compilations and when module ALib BaseCamp is included in the ALib Distribution.
In case the code selector symbol ALIB_DEBUG_MONOMEM is set, additional information retrieved with DbgGetStatistics is included in the generated string.
Returns
Some textual information on the allocation statistics.

Definition at line 306 of file monoallocator.t.hpp.

◆ DbgGetStatistics()

template<typename TAllocator >
const DbgStatistics & DbgGetStatistics ( ) const
inline

Returns allocation statistics for manual performance optimization.

Availability
This method is included only if the code selector symbol ALIB_DEBUG_MONOMEM is set.
Returns
The internal statistics struct.

Definition at line 990 of file monoallocator.hpp.

◆ DbgLock()

template<typename TAllocator >
ALIB_FORCE_INLINE void DbgLock ( bool onOff)
inlinenoexcept

Lock or unlock this allocator. If locked, an ALib assertion is raised if allocations are performed. This can be quite useful to detect allocations with an allocator that is shared between different code entities and to enforce certain allocation contracts.

With release-compilations, this method is empty and optimized out.

See also
Chapter 11.4 Debugging of the Programmer's Manual of this ALib Module.
Parameters
onOffThe state to set.

Definition at line 967 of file monoallocator.hpp.

◆ destructWithExternalBuffer()

template<typename TAllocator >
void destructWithExternalBuffer ( )

This method has to be called before destruction of an instance, in the case that instance was allocated using a special version of the constructors that accept an external Buffer. This will remove the initially given buffer from the list of buffers, and thus this buffer not be deleted. Only if the memory was simply heap-allocated using std::malloc, C++ new operator, or HeapAllocator, and if the memory is intended to be freed, this method may not be called. As a sample, class TLocalAllocator, which uses stack-memory for the first buffer, will call this method in its destructor.

Attention
  1. If this method is not called when needed, this leads to undefined behavior.
  2. If this method is called without the provision of an external buffer on construction, a memory leak occurs. (The first buffer this allocator allocated, will not be freed.)
  3. After this method has been invoked, the instance becomes unusable and is to be destructed in a next step.

Note that as an exception to the rule, this method's name starts with a lowercase letter as if it was protected, while it has to be public.

Definition at line 195 of file monoallocator.t.hpp.

◆ free()

template<typename TAllocator >
void free ( void * mem,
size_t size ) const
inline

This method is empty for this allocator and optimized out. Only if compiler symbol ALIB_DEBUG_ALLOCATIONS is set, the method will overwrite the freed memory with character 0xD2. This is why method allowsMemSplit returns false if that symbol is set and some few optimizations will not be performed in that mode, for example, the reuse of bucket arrays as recycled node objects when resizing hashtables.

Parameters
memThe memory to free.
sizeThe allocated size.

Definition at line 851 of file monoallocator.hpp.

Here is the call graph for this function:

◆ GetStatistics()

template<typename TAllocator >
void GetStatistics ( Statistics & result)

Fills the given result record with statistical information about this allocator.

See also
Method DbgGetStatistics, which delivers further information but is only available with compilation symbol ALIB_DEBUG_MONOMEM set.
Parameters
resultThe object to write the result into. (Will be reset before use.)

Definition at line 271 of file monoallocator.t.hpp.

Here is the call graph for this function:

◆ IsInitialized()

template<typename TAllocator >
bool IsInitialized ( ) const
inlinenoexcept

Tests if non-initializing constructor TMonoAllocator(const char*, std::nullptr_t) was used.

Returns
false if this allocator needs to be initialized by performing a placement-new on this.

Definition at line 740 of file monoallocator.hpp.

◆ nextBuffer()

template<typename TAllocator >
char * nextBuffer ( size_t size,
size_t alignment )
protected

This internal allocation method is called by the allocation interface methods, in case the current request cannot be trivially satisfied.

Implements the overall strategy of this class in respect to oversized blocks, recycling of blocks, etc.

Parameters
sizeThe size of the first object to allocate in the buffer.
alignmentThe allocation alignment of the first object to allocate.
Returns
A pointer to the memory allocated for the object.

Definition at line 213 of file monoallocator.t.hpp.

Here is the call graph for this function:

◆ operator()()

template<typename TAllocator >
lang::AllocatorInterface< TMonoAllocator > operator() ( )
inline

Returns a temporary object (which is usually optimized out together with a call to this operator) providing high-level convenience methods for allocation.

See also
Class lang::AllocatorInterface
Returns
A temporary high-level interface into the allocator.

Definition at line 869 of file monoallocator.hpp.

◆ reallocate()

template<typename TAllocator >
void * reallocate ( void * mem,
size_t oldSize,
size_t newSize,
size_t alignment )
inline

Grows a piece of memory. If a new allocation had to be performed, the existing data is copied. Note that this allocator implementation never shrinks memory, thus if oldSize is greater than newSize, the original memory is returned.

Parameters
memThe memory to reallocate.
oldSizeThe current size of mem.
newSizeThe now required size of mem in bytes. With this allocator this is not an input/output parameter.
alignmentThe (minimum) alignment of the memory block to allocate in bytes. (Has to be the same as before, but this is not tested here). See Chapter 11.1 Alignment of the Programmer's Manual of this module.
Returns
Pointer to the re-allocated memory block.

Definition at line 815 of file monoallocator.hpp.

Here is the call graph for this function:

◆ Reset() [1/2]

template<typename TAllocator >
void Reset ( size_t firstObjectSize,
size_t firstObjectAlignment )
inline

Special version of Reset(Snapshot) which resets this allocator to the first buffer and within that, behind the first object of the given size.
This method is used by class TSharedMonoVal to avoid the need of storing a snapshot behind itself.

If the compiler symbol ALIB_DEBUG_ALLOCATIONS is set, then all freed memory is overwritten with 0xD2. This helps to identify invalid reset operations.

Parameters
firstObjectSizeThe size of the first emplaced object.
firstObjectAlignmentThe alignment of the first emplaced object.

Definition at line 940 of file monoallocator.hpp.

Here is the call graph for this function:

◆ Reset() [2/2]

template<typename TAllocator >
void Reset ( monomem::Snapshot snapshot = Snapshot())

Resets this allocator to the given Snapshot. Parameter snapshot is defaulted with a default-constructed Snapshot, which completely resets the allocator.

With a reset, the memory buffers which had been allocated after taking the given snapshot, are not released back to the operating system, but re-used with future monotonic allocations.

This method is useful in cases where some permanent objects which are allocated first have to be preserved with resets.

Note that snapshots taken after the given one become invalid. This is because class Snapshot is only a simple lightweight class that marks the currently used buffer and its fill level.

Parameters
snapshotThe snapshot to reset to.

Definition at line 108 of file monoallocator.t.hpp.

Here is the call graph for this function:

◆ TakeSnapshot()

template<typename TAllocator >
Snapshot TakeSnapshot ( )
inline

Saves the current state of the allocator and returns this information as a Snapshot value. Such snapshots may be passed to method Reset(Snapshot).

Note that the actual memory is not copied and restored. In this respect the word "Snapshot" is overstating. What is stored are the current use of memory, but not it's contents.

Returns
A (lightweight) snapshot value object.

Definition at line 903 of file monoallocator.hpp.


The documentation for this class was generated from the following files: