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.
#define
in RooArgSet.h / RooDataSet.hIf 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. | |
MemPoolForRooSets (const MemPoolForRooSets &)=delete | |
MemPoolForRooSets (MemPoolForRooSets &&)=delete | |
~MemPoolForRooSets () | |
Destructor. Should not be called when RooArgSets or RooDataSets are still alive. | |
void * | allocate (std::size_t bytes) |
Allocate memory for the templated set type. Fails if bytes != sizeof(RooSet_t). | |
bool | deallocate (void *ptr) |
Deallocate memory for the templated set type if in pool. | |
bool | empty () const |
Test if pool is empty. | |
MemPoolForRooSets & | operator= (const MemPoolForRooSets &)=delete |
MemPoolForRooSets & | operator= (MemPoolForRooSets &&)=delete |
void | prune () |
Free memory in arenas that don't have space and no users. | |
void | teardown () |
Set pool to teardown mode (at program end). | |
Private Member Functions | |
void | newArena () |
RooFit relies on unique pointers for RooArgSets. | |
Private Attributes | |
std::vector< Arena > | fArenas |
bool | fTeardownMode {false} |
|
inline |
Create empty mem pool.
Definition at line 206 of file MemPoolForRooSets.h.
|
delete |
|
delete |
|
inline |
Destructor. Should not be called when RooArgSets or RooDataSets are still alive.
Definition at line 214 of file MemPoolForRooSets.h.
|
inline |
Allocate memory for the templated set type. Fails if bytes != sizeof(RooSet_t).
Definition at line 227 of file MemPoolForRooSets.h.
|
inline |
Deallocate memory for the templated set type if in pool.
Definition at line 253 of file MemPoolForRooSets.h.
|
inline |
Test if pool is empty.
Definition at line 294 of file MemPoolForRooSets.h.
|
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.
|
delete |
|
delete |
|
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.
|
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.
|
private |
Definition at line 335 of file MemPoolForRooSets.h.
|
private |
Definition at line 336 of file MemPoolForRooSets.h.