Logo ROOT  
Reference Guide
MemPoolForRooSets Class Reference

Memory pool for RooArgSet and RooDataSet.

RooArgSet and RooDataSet were using a mempool that guarantees that allocating, de-allocating and re-allocating a set does not yield the same pointer. Since both were using the same logic, the functionality has been put in this class. This class solves RooFit's static destruction order problems by intentionally leaking arenas of the mempool that still contain live objects at the end of the program.

When the set types are compared based on a unique ID instead of their pointer, one can go back to normal memory management, and this class becomes obsolete.

Definition at line 26 of file RooArgSet.h.

Classes

struct  Arena
 

Public Member Functions

 MemPoolForRooSets ()
 Create empty mem pool. More...
 
 MemPoolForRooSets (const MemPoolForRooSets &)=delete
 
 MemPoolForRooSets (MemPoolForRooSets &&)=delete
 
 ~MemPoolForRooSets ()
 Destructor. Should not be called when RooArgSets or RooDataSets are still alive. More...
 
voidallocate (std::size_t bytes)
 Allocate memory for the templated set type. Fails if bytes != sizeof(RooSet_t). More...
 
bool deallocate (void *ptr)
 Deallocate memory for the templated set type if in pool. More...
 
bool empty () const
 Test if pool is empty. More...
 
MemPoolForRooSetsoperator= (const MemPoolForRooSets &)=delete
 
MemPoolForRooSetsoperator= (MemPoolForRooSets &&)=delete
 
void prune ()
 Free memory in arenas that don't have space and no users. More...
 
void teardown ()
 Set pool to teardown mode (at program end). More...
 

Private Member Functions

void newArena ()
 RooFit relies on unique pointers for RooArgSets. More...
 

Private Attributes

std::vector< ArenafArenas
 
bool fTeardownMode {false}
 

#include <RooArgSet.h>

Constructor & Destructor Documentation

◆ MemPoolForRooSets() [1/3]

MemPoolForRooSets::MemPoolForRooSets ( )
inline

Create empty mem pool.

Definition at line 161 of file MemPoolForRooSets.h.

◆ MemPoolForRooSets() [2/3]

MemPoolForRooSets::MemPoolForRooSets ( const MemPoolForRooSets )
delete

◆ MemPoolForRooSets() [3/3]

MemPoolForRooSets::MemPoolForRooSets ( MemPoolForRooSets &&  )
delete

◆ ~MemPoolForRooSets()

MemPoolForRooSets::~MemPoolForRooSets ( )
inline

Destructor. Should not be called when RooArgSets or RooDataSets are still alive.

Definition at line 169 of file MemPoolForRooSets.h.

Member Function Documentation

◆ allocate()

void* MemPoolForRooSets::allocate ( std::size_t  bytes)
inline

Allocate memory for the templated set type. Fails if bytes != sizeof(RooSet_t).

Definition at line 184 of file MemPoolForRooSets.h.

◆ deallocate()

bool MemPoolForRooSets::deallocate ( void ptr)
inline

Deallocate memory for the templated set type if in pool.

Returns
True if element was in pool.

Definition at line 204 of file MemPoolForRooSets.h.

◆ empty()

bool MemPoolForRooSets::empty ( ) const
inline

Test if pool is empty.

Definition at line 243 of file MemPoolForRooSets.h.

◆ newArena()

void MemPoolForRooSets::newArena ( )
inlineprivate

RooFit relies on unique pointers for RooArgSets.

Here, memory has to be allocated until a completely new chunk of memory is encountered. As soon as RooXXXSets can be identified with a unique ID, this becomes obsolete.

Definition at line 267 of file MemPoolForRooSets.h.

◆ operator=() [1/2]

MemPoolForRooSets& MemPoolForRooSets::operator= ( const MemPoolForRooSets )
delete

◆ operator=() [2/2]

MemPoolForRooSets& MemPoolForRooSets::operator= ( MemPoolForRooSets &&  )
delete

◆ prune()

void MemPoolForRooSets::prune ( )
inline

Free memory in arenas that don't have space and no users.

In fTeardownMode, it will also delete the arena that still has space.

Definition at line 227 of file MemPoolForRooSets.h.

◆ teardown()

void MemPoolForRooSets::teardown ( )
inline

Set pool to teardown mode (at program end).

Will prune all empty arenas. Non-empty arenas will survive until all contained elements are deleted. They may therefore leak if not all elements are destructed.

Definition at line 253 of file MemPoolForRooSets.h.

Member Data Documentation

◆ fArenas

std::vector<Arena> MemPoolForRooSets::fArenas
private

Definition at line 284 of file MemPoolForRooSets.h.

◆ fTeardownMode

bool MemPoolForRooSets::fTeardownMode {false}
private

Definition at line 285 of file MemPoolForRooSets.h.


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