Logo ROOT  
Reference Guide
MemPoolForRooSets< RooSet_t, POOLSIZE > Class Template Reference

template<class RooSet_t, std::size_t POOLSIZE>
class MemPoolForRooSets< RooSet_t, POOLSIZE >

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 35 of file MemPoolForRooSets.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 </home/sftnight/build/workspace/root-makedoc-v622/rootspi/rdoc/src/v6-22-00-patches/roofit/roofitcore/src/MemPoolForRooSets.h>

Constructor & Destructor Documentation

◆ MemPoolForRooSets() [1/3]

template<class RooSet_t , std::size_t POOLSIZE>
MemPoolForRooSets< RooSet_t, POOLSIZE >::MemPoolForRooSets ( )
inline

Create empty mem pool.

Definition at line 181 of file MemPoolForRooSets.h.

◆ MemPoolForRooSets() [2/3]

template<class RooSet_t , std::size_t POOLSIZE>
MemPoolForRooSets< RooSet_t, POOLSIZE >::MemPoolForRooSets ( const MemPoolForRooSets< RooSet_t, POOLSIZE > &  )
delete

◆ MemPoolForRooSets() [3/3]

template<class RooSet_t , std::size_t POOLSIZE>
MemPoolForRooSets< RooSet_t, POOLSIZE >::MemPoolForRooSets ( MemPoolForRooSets< RooSet_t, POOLSIZE > &&  )
delete

◆ ~MemPoolForRooSets()

template<class RooSet_t , std::size_t POOLSIZE>
MemPoolForRooSets< RooSet_t, POOLSIZE >::~MemPoolForRooSets ( )
inline

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

Definition at line 189 of file MemPoolForRooSets.h.

Member Function Documentation

◆ allocate()

template<class RooSet_t , std::size_t POOLSIZE>
void * MemPoolForRooSets< RooSet_t, POOLSIZE >::allocate ( std::size_t  bytes)
inline

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

Definition at line 202 of file MemPoolForRooSets.h.

◆ deallocate()

template<class RooSet_t , std::size_t POOLSIZE>
bool MemPoolForRooSets< RooSet_t, POOLSIZE >::deallocate ( void ptr)
inline

Deallocate memory for the templated set type if in pool.

Returns
True if element was in pool.

Definition at line 228 of file MemPoolForRooSets.h.

◆ empty()

template<class RooSet_t , std::size_t POOLSIZE>
bool MemPoolForRooSets< RooSet_t, POOLSIZE >::empty ( ) const
inline

Test if pool is empty.

Definition at line 267 of file MemPoolForRooSets.h.

◆ newArena()

template<class RooSet_t , std::size_t POOLSIZE>
void MemPoolForRooSets< RooSet_t, POOLSIZE >::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 291 of file MemPoolForRooSets.h.

◆ operator=() [1/2]

template<class RooSet_t , std::size_t POOLSIZE>
MemPoolForRooSets & MemPoolForRooSets< RooSet_t, POOLSIZE >::operator= ( const MemPoolForRooSets< RooSet_t, POOLSIZE > &  )
delete

◆ operator=() [2/2]

template<class RooSet_t , std::size_t POOLSIZE>
MemPoolForRooSets & MemPoolForRooSets< RooSet_t, POOLSIZE >::operator= ( MemPoolForRooSets< RooSet_t, POOLSIZE > &&  )
delete

◆ prune()

template<class RooSet_t , std::size_t POOLSIZE>
void MemPoolForRooSets< RooSet_t, POOLSIZE >::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 251 of file MemPoolForRooSets.h.

◆ teardown()

template<class RooSet_t , std::size_t POOLSIZE>
void MemPoolForRooSets< RooSet_t, POOLSIZE >::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 277 of file MemPoolForRooSets.h.

Member Data Documentation

◆ fArenas

template<class RooSet_t , std::size_t POOLSIZE>
std::vector<Arena> MemPoolForRooSets< RooSet_t, POOLSIZE >::fArenas
private

Definition at line 308 of file MemPoolForRooSets.h.

◆ fTeardownMode

template<class RooSet_t , std::size_t POOLSIZE>
bool MemPoolForRooSets< RooSet_t, POOLSIZE >::fTeardownMode {false}
private

Definition at line 309 of file MemPoolForRooSets.h.


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