Determines if the instance was dynamically allocated on the heap. More...

#include <HeapTracked.h>

Inheritance diagram for Reference::HeapTracked:
Reference::Able Alias Callback< Type > Callback< std::string > CommandLine::Item CommandLine::Menu FTransform::Agent FTransform::Bench FTransform::Plan FTransform::Plan2 FunctorBase Interpolation JenetAnderson98 JenetAnderson98::EquationA5 JenetAnderson98::Probability LogFile Mount OwnStream PolynomialFit Pulsar::Generator Pulsar::Parameters Pulsar::Parameters::Lookup Pulsar::Predictor Pulsar::Site Registry::Entry< Parent > RobustEstimateZapper SplineFit TemporaryFile TextEditor< T > TextIndex TextInterface::Name TextInterface::Parser TextInterface::Value TextLoop

Public Member Functions

 HeapTracked ()
 Default constructor.
 
 HeapTracked (const HeapTracked &)
 Copy constructor.
 
HeapTrackedoperator= (const HeapTracked &)
 Assignment operator.
 
virtual ~HeapTracked ()
 Destructor.
 
bool __is_on_heap () const
 Return true if this instance is found in heap addresses.
 

Static Public Member Functions

static void * operator new (size_t size, void *ptr=0)
 Records the addresses of new instances allocated on the heap.
 
static void operator delete (void *location, void *ptr)
 Placement delete overload to match the placement new overload.
 
static void operator delete (void *location)
 Regular delete overload.
 
static size_t get_heap_queue_size ()
 Return the number of heap addresses awaiting processing.
 

Friends

class Able
 

Detailed Description

Determines if the instance was dynamically allocated on the heap.

The HeapTracked class overloads operator new in order to store the addresses of instances that have been dynamically allocated on the heap (see the HeapTracked class and the discussion in Item 27 of Scott Meyers, More Effective C++).

As the number of objects constructed at any one time will generally be much smaller than the number of objects in existence at the time of deletion, it is more efficient to search the heap addresses during construction and to set the __heap_state attribute accordingly. However, in order to handle the possibility of multiple inheritance, it is necessary for the __is_on_heap method to perform a dynamic cast of the "this" pointer before searching the heap addresses. As this dynamic cast does not work inside the constructor of a virtually inherited class, it is not possible to set the __heap_state attribute during construction.

Therefore, in order to improve the efficiency of the __is_on_heap search, it is advised to call the __is_on_heap method as soon as possible after construction of the object. This is done by the Reference::Able::__reference method, which is called by the Reference::To template class when its assigment operator is called.


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

Generated using doxygen 1.8.17