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. RooFit relies on this, unfortunately, because it compares the pointers of RooArgSets to figure out caching, e.g. of integrals.

Since both RooArgSet and RooDataSet were using the same logic to manage their memory pools, the functionality has been put here in a single place. The introduction of this common mempool also solved RooFit's static destruction order problems by letting arenas of the mempool leak if RooArgSets are still alive. This is necessary if the tear down of the mempool happens before all RooArgSets of the entire process have been deleted. This might e.g. happen in static configs for integrators or when a plot of a PDF is alive when quitting the interpreter.

If this memory pool seems to leak memory:

  • It is likely a leaking RooArgSet / RooDataSet
  • Disable the memory pool using the #define in RooArgSet.h / RooDataSet.h
  • Rerun the leak check to find the leaking RooXSet
  • Fix it
  • Re-enable the memory pool
Warning
Disabling the memory pools might seem to work at first sight, but can eventually lead to wrong computations. This would happen if the operating system decides to assign the same memory address when a RooArgSet is deleted and re-allocated, and both the deleted as well as the new set happen to be used in the same computation graph. RooFit will think that the cache doesn't have to be recalculated, and will return an outdated result. These errors are hard to track down, because they might only happen in a specific toy MC run on a specific OS / architecture.

How to get rid of the memory pool

If RooArgSet or RooDataSet were compared based on a unique ID instead of their pointer, this class would become obsolete. It should be tested, though, if handing memory management over to the OS has an impact on speed. This is less of a worry, though, because OSs got smarter over RooFit's life time.

Definition at line 60 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-master/rootspi/rdoc/src/master/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 206 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 214 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 227 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 253 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 294 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 318 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. Arenas are never deleted, because the pointers of RooArgSets/RooDataSets need to be unique for RooFit's caching to work. The arenas only give back the memory to the OS.

Definition at line 278 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 304 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 335 of file MemPoolForRooSets.h.

◆ fTeardownMode

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

Definition at line 336 of file MemPoolForRooSets.h.


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