Lumiera 0.pre.04
»edit your freedom«
Loading...
Searching...
No Matches
TrackingAllocator Class Reference

#include "lib/test/tracking-allocator.hpp"

Description

Generic low-level allocator attached to tracking MemoryPool.

Effectively this is a shared handle front-end to the MemoryPool, and new distinct pools are generated (and discarded) on demand, keyed by a pool-ID. A global (singleton) pool is used when no pool-ID is explicitly given.

Definition at line 83 of file tracking-allocator.hpp.

Public Types

using Location = void *
 

Static Public Attributes

static EventLog log {"test::TrackingAllocator"}
 

Static Public Member Functions

static HashVal checksum (Literal pool=GLOBAL)
 get Checksum for specific mem-pool
 
static size_t use_count (Literal pool=GLOBAL)
 determine number of active front-end handles
 
static size_t numAlloc (Literal pool=GLOBAL)
 get active allocation count for mem-pool
 
static size_t numBytes (Literal pool=GLOBAL)
 calculate currently allotted Bytes for mem-pool
 

Public Member Functions

 TrackingAllocator ()
 can be default created to attach to a common pool
 
 TrackingAllocator (Literal id)
 create a separate, marked memory pool
 
Location allocate (size_t n)
 Allot a memory block of given size bytes.
 
void deallocate (Location, size_t=0) noexcept
 Discard and forget an allocation created through this allocator.
 
bool manages (Location) const
 probe if this allocator pool did allocate the given memory location
 
size_t getSize (Location) const
 retrieve the registered size of this allocation, if known.
 
HashVal getID (Location) const
 retrieve the internal registration ID for this allocation.
 
Literal poolID () const
 

Friends

bool operator== (TrackingAllocator const &a1, TrackingAllocator const &a2)
 
bool operator!= (TrackingAllocator const &a1, TrackingAllocator const &a2)
 

Private Attributes

PoolHandle mem_
 

Constructor & Destructor Documentation

◆ TrackingAllocator() [1/2]

can be default created to attach to a common pool

Definition at line 172 of file tracking-allocator.cpp.

◆ TrackingAllocator() [2/2]

create a separate, marked memory pool

Definition at line 176 of file tracking-allocator.cpp.

Member Typedef Documentation

◆ Location

using Location = void*

Definition at line 96 of file tracking-allocator.hpp.

Member Function Documentation

◆ allocate()

TrackingAllocator::Location allocate ( size_t  bytes)

Allot a memory block of given size bytes.

This allocation is recorded in the associated MemoryPool and proper deallocation can thus be verified.

Returns
a void* to the start of the bare memory location

Definition at line 188 of file tracking-allocator.cpp.

References TrackingAllocator::mem_.

Referenced by TrackAlloc< TY >::allocate(), TrackingFactory::create(), and TestTracking_test::demonstrate_checkAllocator().

+ Here is the caller graph for this function:

◆ deallocate()

void deallocate ( Location  loc,
size_t  bytes = 0 
)
noexcept

Discard and forget an allocation created through this allocator.

The bytes argument serves as sanity check (since the actual allocation size is recorded anyway); a mismatch is logged as error, yet silently ignored.

Definition at line 201 of file tracking-allocator.cpp.

Referenced by TrackAlloc< TY >::deallocate(), TestTracking_test::demonstrate_checkAllocator(), and TrackingFactory::dispose().

+ Here is the caller graph for this function:

◆ manages()

bool manages ( Location  memLoc) const

probe if this allocator pool did allocate the given memory location

Definition at line 311 of file tracking-allocator.cpp.

References TrackingAllocator::mem_.

Referenced by TestTracking_test::demonstrate_checkAllocator().

+ Here is the caller graph for this function:

◆ getSize()

size_t getSize ( Location  memLoc) const

retrieve the registered size of this allocation, if known.

Definition at line 319 of file tracking-allocator.cpp.

References TrackingAllocator::mem_.

Referenced by TestTracking_test::demonstrate_checkAllocator().

+ Here is the caller graph for this function:

◆ getID()

HashVal getID ( Location  memLoc) const

retrieve the internal registration ID for this allocation.

Definition at line 329 of file tracking-allocator.cpp.

References TrackingAllocator::mem_.

Referenced by TestTracking_test::demonstrate_checkAllocator().

+ Here is the caller graph for this function:

◆ poolID()

Literal poolID ( ) const

Definition at line 338 of file tracking-allocator.cpp.

References TrackingAllocator::mem_.

Referenced by TrackingAllocator::checksum(), TrackingFactory::create(), TrackingFactory::dispose(), TrackingAllocator::numAlloc(), TrackingAllocator::numBytes(), and TrackingAllocator::use_count().

+ Here is the caller graph for this function:

◆ checksum()

HashVal checksum ( Literal  pool = GLOBAL)
static

get Checksum for specific mem-pool

Definition at line 278 of file tracking-allocator.cpp.

References TrackingAllocator::poolID().

Referenced by SeveralBuilder_test::check_CustomAllocator(), and TestTracking_test::demonstrate_checkAllocator().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ use_count()

size_t use_count ( Literal  pool = GLOBAL)
static

determine number of active front-end handles

Definition at line 286 of file tracking-allocator.cpp.

References TrackingAllocator::poolID().

Referenced by SeveralBuilder_test::check_CustomAllocator(), and TestTracking_test::demonstrate_checkAllocator().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ numAlloc()

size_t numAlloc ( Literal  pool = GLOBAL)
static

get active allocation count for mem-pool

Definition at line 294 of file tracking-allocator.cpp.

References TrackingAllocator::poolID().

Referenced by SeveralBuilder_test::check_CustomAllocator(), and TestTracking_test::demonstrate_checkAllocator().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ numBytes()

size_t numBytes ( Literal  pool = GLOBAL)
static

calculate currently allotted Bytes for mem-pool

Definition at line 302 of file tracking-allocator.cpp.

References TrackingAllocator::poolID().

Referenced by SeveralBuilder_test::check_CustomAllocator(), and TestTracking_test::demonstrate_checkAllocator().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ mem_

◆ log

Friends And Related Symbol Documentation

◆ operator==

bool operator== ( TrackingAllocator const &  a1,
TrackingAllocator const &  a2 
)
friend

Definition at line 103 of file tracking-allocator.hpp.

◆ operator!=

bool operator!= ( TrackingAllocator const &  a1,
TrackingAllocator const &  a2 
)
friend

Definition at line 108 of file tracking-allocator.hpp.

+ Inheritance diagram for TrackingAllocator:
+ Collaboration diagram for TrackingAllocator:

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