49#ifndef ROOFIT_ROOFITCORE_SRC_MEMPOOLFORROOSETS_H_
50#define ROOFIT_ROOFITCORE_SRC_MEMPOOLFORROOSETS_H_
59template <
class RooSet_t, std::
size_t POOLSIZE>
64 :
ownedMemory{static_cast<RooSet_t *>(
TStorage::ObjectAlloc(2 * POOLSIZE * sizeof(RooSet_t)))},
80 other.ownedMemory =
nullptr;
97 other.ownedMemory =
nullptr;
112 std::cerr << __FILE__ <<
":" << __LINE__ <<
"Deleting arena " <<
ownedMemory <<
" with use count " <<
refCount
121 bool inPool(
const RooSet_t *
const ptr)
const {
125 bool inPool(
const void *
const ptr)
const
127 return inPool(
static_cast<const RooSet_t * const
>(ptr));
146 for(std::size_t
i = 0;
i < POOLSIZE; ++
i) {
173 const std::size_t
index = ( (
reinterpret_cast<const char *
>(ptr) -
reinterpret_cast<const char *
>(
memBegin)) / 2) /
sizeof(RooSet_t);
176 std::cerr <<
"Double delete of " << ptr <<
" at index " <<
index <<
" in Arena with refCount " <<
refCount
177 <<
".\n\tArena: |" <<
memBegin <<
"\t" << ptr <<
"\t" <<
memEnd <<
"|" << std::endl;
200 std::array<int, POOLSIZE>
cycle = {{}};
218 std::cerr << __PRETTY_FUNCTION__;
220 std::cerr <<
" The mem pool being deleted is not empty. This will lead to crashes."
229 if (
bytes !=
sizeof(RooSet_t))
230 throw std::bad_alloc();
236 void * ptr =
fArenas.back().tryAllocate();
238 if (ptr ==
nullptr) {
241 ptr =
fArenas.back().tryAllocate();
244 assert(ptr !=
nullptr);
255 bool deallocSuccess =
false;
258 [ptr](
Arena& arena){return arena.tryDeallocate(ptr);})) {
259 deallocSuccess =
true;
267 return deallocSuccess;
286 std::remove_if(
fArenas.begin(),
fArenas.end(), [](
Arena& ar){return ar.ownedMemory == nullptr;}),
296 return std::all_of(
fArenas.begin(),
fArenas.end(), [](
const Arena & ar) { return ar.empty(); });
319 std::vector<Arena> failedAllocs;
323 [&ar](
Arena& other){return ar.memoryOverlaps(other);})) {
324 fArenas.emplace_back(std::move(ar));
328 failedAllocs.push_back(std::move(ar));
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t bytes
~MemPoolForRooSets()
Destructor. Should not be called when RooArgSets or RooDataSets are still alive.
void prune()
Free memory in arenas that don't have space and no users.
MemPoolForRooSets & operator=(const MemPoolForRooSets &)=delete
MemPoolForRooSets(const MemPoolForRooSets &)=delete
void newArena()
RooFit relies on unique pointers for RooArgSets.
MemPoolForRooSets & operator=(MemPoolForRooSets &&)=delete
MemPoolForRooSets()
Create empty mem pool.
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.
MemPoolForRooSets(MemPoolForRooSets &&)=delete
void teardown()
Set pool to teardown mode (at program end).
std::vector< Arena > fArenas
bool empty() const
Test if pool is empty.
bool tryDeallocate(void *ptr)
void tryFree(bool freeNonFull)
bool inPool(const void *const ptr) const
bool memoryOverlaps(const Arena &other) const
const RooSet_t * memBegin
std::array< int, POOLSIZE > cycle
std::bitset< POOLSIZE > assigned
Arena & operator=(Arena &&other)
bool inPool(const RooSet_t *const ptr) const
Arena(const Arena &)=delete
Arena & operator=(const Arena &)=delete