Lumiera  0.pre.03
»edit your freedom«
tracking-allocator.hpp File Reference

Go to the source code of this file.

Description

Unittest helper code: a custom allocator to track memory usage.

By registering each allocation and deallocation, correct memory handling can be verified and memory usage can be investigated in practice.

TrackingAllocator
The foundation is to allow raw memory allocations, which are attached and tracked within some memory pool, allowing to investigate the number of allocations, number of currently allotted bytes and a checksum. Moreover, all relevant actions are logged into an lib::test::EventLog. By default a common global MemoryPool is used, while it is possible to carry out all those operations also on a dedicated pool; the user visible »allocators« are actually shared-ownership smart-handles.
TrackingFactory
Built on top is a standard factory to create and destroy arbitrary object instances, with the corresponding allocations attached to the underlying MemoryPool
C++ standard allocator adapter
A variation of this is the TrackAlloc<TY> template, which can be used as custom allocator adapter within STL containers
Remarks
these classes also work in concert with the building blocks from allocator-handle.hpp; notably it is possible to create a OwnUniqueAdapter front-end for fabricating unique_ptr
Warning
deliberately not threadsafe
  • generally speaking, allocation should be kept outside of any multithreaded environment, or at least requires dedicated care beyond any standard scheme
  • this is a test feature...
See also
TestTracking_test

Definition in file tracking-allocator.hpp.

#include "lib/error.hpp"
#include "lib/symbol.hpp"
#include "lib/nocopy.hpp"
#include "lib/hash-value.h"
#include "lib/test/event-log.hpp"
#include "lib/format-string.hpp"
#include <utility>
#include <memory>

Classes

class  TrackAlloc< TY >
 C++ standard compliant custom allocator adapter backed by the TrackingAllocator and the MemoryPool denoted at construction. More...
 
class  TrackingAllocator
 Generic low-level allocator attached to tracking MemoryPool. More...
 
class  TrackingFactory
 Generic object factory backed by TrackingAllocator. More...
 

Typedefs

using PoolHandle = std::shared_ptr< MemoryPool >
 

Variables

const Symbol GLOBAL {"GLOBAL"}
 

Namespaces

 lib
 Implementation namespace for support and library code.