46 #ifndef LIB_TEST_TRACKING_ALLOCATOR_H 47 #define LIB_TEST_TRACKING_ALLOCATOR_H 67 const Symbol GLOBAL{
"GLOBAL"};
96 using Location =
void*;
98 [[nodiscard]] Location
allocate (
size_t n);
99 void deallocate (Location,
size_t =0) noexcept;
105 return a1.mem_ == a2.mem_;
110 return not (a1 == a2);
117 size_t getSize(Location)
const;
138 template<
typename TY>
154 using value_type = TY;
162 [[nodiscard]] TY*
allocate (
size_t cnt);
183 template<
class TY,
typename...ARGS>
187 Location loc =
allocate(
sizeof(TY));
188 log.
call (poolID(),
"create-"+util::typeStr<TY>(), std::forward<ARGS> (args)...);
190 return new(loc) TY (std::forward<ARGS> (args)...);
192 catch (std::exception& mishap)
194 log.
error (
util::_Fmt{
"CtorFail: type=%s, problem:%s"} % util::typeStr<TY>() % mishap.what());
199 log.
error (
"CtorFail: unknown cause");
211 log.
warn(
"dispose(nullptr)");
214 log.
call (poolID(),
"destroy-"+util::typeStr<TY>());
225 template<
typename TY>
236 template<
typename TY>
Location allocate(size_t n)
Allot a memory block of given size bytes.
static HashVal checksum(Literal pool=GLOBAL)
get Checksum for specific mem-pool
C++ standard compliant custom allocator adapter backed by the TrackingAllocator and the MemoryPool de...
size_t getSize(Location) const
retrieve the registered size of this allocation, if known.
EventLog & warn(string text)
Log a warning entry.
std::true_type propagate_on_container_swap
otherwise they would have to deallocate cross-wise
Support for verifying the occurrence of events from unit tests.
inline string literal This is a marker type to indicate that
Helper to log and verify the occurrence of events.
Generic low-level allocator attached to tracking MemoryPool.
static size_t numBytes(Literal pool=GLOBAL)
calculate currently allotted Bytes for mem-pool
TrackingFactory(TrackingAllocator const &anchor)
attach to the given TrackingAllocator and MemoryPool
bool manages(Location) const
probe if this allocator pool did allocate the given memory location
A front-end for using printf-style formatting.
Implementation namespace for support and library code.
Generic object factory backed by TrackingAllocator.
void dispose(TY *elm) noexcept
destroy the given element and discard the associated memory and registration
TY * create(ARGS &&...args)
create new element with an allocation registered in the backing MemoryPool
void deallocate(Location, size_t=0) noexcept
Discard and forget an allocation created through this allocator.
Token or Atom with distinct identity.
Mix-Ins to allow or prohibit various degrees of copying and cloning.
std::true_type propagate_on_container_copy_assignment
for sake of consistency
Marker types to indicate a literal string and a Symbol.
EventLog & call(string target, string function)
Log occurrence of a function call with no arguments.
HashVal getID(Location) const
retrieve the internal registration ID for this allocation.
TY * allocate(size_t cnt)
C++ standard allocator API : allot raw memory for cnt elements of type TY.
std::true_type propagate_on_container_move_assignment
otherwise all elements must be copied
Lumiera error handling (C++ interface).
void deallocate(TY *, size_t) noexcept
C++ standard allocator API : clear an existing allocation, which must have been allocated into the sa...
Hash value types and utilities.
size_t HashVal
a STL compatible hash value
static size_t numAlloc(Literal pool=GLOBAL)
get active allocation count for mem-pool
static size_t use_count(Literal pool=GLOBAL)
determine number of active front-end handles
TrackingAllocator()
can be default created to attach to a common pool
TrackAlloc(TrackAlloc< X > const &anchor)
cross-building for another type, using a common pool
EventLog & error(string text)
Log an error note.