41#include <unordered_map>
44using std::make_shared;
76 using AllocTab = std::unordered_map<const Location, Allocation, LocationHash>;
111 template<
typename...XS>
118 template<
typename...ARGS>
130 using PoolTab = std::unordered_map<Literal, std::weak_ptr<MemoryPool>>;
150 return poolReg().fetch_or_create (poolID);
155 PoolRegistry::fetch_or_create (
Literal poolID)
157 auto& entry = pools_[poolID];
158 auto handle = entry.lock();
159 if (handle)
return handle;
162 PoolHandle newPool = make_shared<MemoryPool> (poolID);
173 : mem_{PoolRegistry::locate(GLOBAL)}
177 : mem_{PoolRegistry::locate(id)}
191 return mem_->addAlloc (bytes)
204 mem_->discardAlloc (loc, bytes);
213 ASSERT (not contains (
allocs_, loc));
215 logAlloc (
poolID_,
"allocate", bytes, newAlloc.
entryID, showAdr(loc));
217 return allocs_.emplace (loc, move(newAlloc))
228 ASSERT (entry.buff.front() == loc);
229 if (entry.buff.size() != bytes)
230 logAlarm (
"SizeMismatch", bytes,
"≠", entry.buff.size(), entry.entryID, showAdr(loc));
232 logAlloc (
poolID_,
"deallocate", bytes, entry.entryID, bytes, showAdr(loc));
237 logAlarm (
"FreeUnknown", bytes, showAdr(loc));
265 .transform ([](
auto& it){
return it->second.buff.size(); })
281 return pool->getChecksum();
289 return pool.use_count() - 1;
297 return pool->getAllocationCnt();
305 return pool->calcAllocSize();
314 return bool(
mem_->findAlloc (memLoc));
322 auto* entry =
mem_->findAlloc (memLoc);
323 return entry? entry->buff.size()
332 auto* entry =
mem_->findAlloc (memLoc);
333 return entry? entry->entryID
341 return mem_->getPoolID();
Access point to singletons and other kinds of dependencies designated by type.
Managed uninitialised Heap-allocated storage with array like access.
Helper to log and verify the occurrence of events.
EventLog & error(string text)
Log an error note.
EventLog & call(string target, string function)
Log occurrence of a function call with no arguments.
size_t getAllocationCnt() const
size_t calcAllocSize() const
Allocation & addAlloc(size_t bytes)
Allocation const * findAlloc(Location) const
HashVal getChecksum() const
std::unordered_map< const Location, Allocation, LocationHash > AllocTab
Literal getPoolID() const
void discardAlloc(void *loc, size_t)
void deallocate(Location, size_t=0) noexcept
Discard and forget an allocation created through this allocator.
static size_t numAlloc(Literal pool=GLOBAL)
get active allocation count for mem-pool
Location allocate(size_t n)
Allot a memory block of given size bytes.
bool manages(Location) const
probe if this allocator pool did allocate the given memory location
TrackingAllocator()
can be default created to attach to a common pool
HashVal getID(Location) const
retrieve the internal registration ID for this allocation.
static size_t numBytes(Literal pool=GLOBAL)
calculate currently allotted Bytes for mem-pool
static size_t use_count(Literal pool=GLOBAL)
determine number of active front-end handles
size_t getSize(Location) const
retrieve the registered size of this allocation, if known.
static HashVal checksum(Literal pool=GLOBAL)
get Checksum for specific mem-pool
keep track of any distinct memory pools used
std::unordered_map< Literal, std::weak_ptr< MemoryPool > > PoolTab
Types marked with this mix-in may be moved but not copied.
Any copy and copy construction prohibited.
Singleton services and Dependency Injection.
Building tree expanding and backtracking evaluations within hierarchical scopes.
Depend< PoolRegistry > poolReg
Depend< MemoryPool > globalPool
singleton for default pool
void logAlarm(XS const &...xs)
void logAlloc(Literal pool, string fun, ARGS const &...args)
std::shared_ptr< MemoryPool > PoolHandle
Implementation namespace for support and library code.
auto explore(IT &&srcSeq)
start building a IterExplorer by suitably wrapping the given iterable source.
size_t HashVal
a STL compatible hash value
Test runner and basic definitions for tests.
ostream & showAdr(ostream &stream, void const *addr)
preconfigured format for pretty-printing of addresses
bool contains(MAP &map, typename MAP::key_type const &key)
shortcut for containment test on a map
string joinDash(ARGS const &...args)
shortcut: join directly with dashes
registration entry to maintain a single allocation
UninitialisedDynBlock< byte > buff
HashVal operator()(Location const &loc) const
Unittest helper code: a custom allocator to track memory usage.
A raw memory block with proper alignment and array access.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...