10 #ifndef ROOT_Minuit2_StackAllocator 11 #define ROOT_Minuit2_StackAllocator 20 #ifdef MN_USE_STACK_ALLOC 21 #define _MN_NO_THREAD_SAVE_ 57 enum {default_size = 524288};
60 #ifdef _MN_NO_THREAD_SAVE_ 62 fStack =
new unsigned char[default_size];
69 #ifdef _MN_NO_THREAD_SAVE_ 71 if(fStack)
delete [] fStack;
76 #ifdef _MN_NO_THREAD_SAVE_ 77 if(fStack == 0) fStack =
new unsigned char[default_size];
78 int nAlloc = AlignedSize(nBytes);
79 CheckOverflow(nAlloc);
84 WriteInt( fStackOffset, fStackOffset+nAlloc);
86 WriteInt( fStackOffset + nAlloc -
sizeof(
int), fStackOffset);
88 void* result = fStack + fStackOffset +
sizeof(int);
89 fStackOffset += nAlloc;
92 #ifdef DEBUG_ALLOCATOR 97 void* result =
malloc(nBytes);
98 if (!result)
throw std::bad_alloc();
105 #ifdef _MN_NO_THREAD_SAVE_ 107 int delBlock = ToInt(p);
108 int nextBlock = ReadInt( delBlock);
109 int previousBlock = ReadInt( nextBlock -
sizeof(
int));
110 if ( nextBlock == fStackOffset) {
112 fStackOffset = previousBlock;
116 int nextNextBlock = ReadInt(nextBlock);
117 WriteInt( nextNextBlock -
sizeof(
int), previousBlock);
119 WriteInt( previousBlock, nextNextBlock);
123 #ifdef DEBUG_ALLOCATOR 134 int* ip = (
int*)(fStack+offset);
145 int* ip =
reinterpret_cast<int*
>(fStack+offset);
150 unsigned char*
pc =
static_cast<unsigned char*
>(p);
154 int userBlock = pc - fStack;
155 return userBlock -
sizeof(int);
159 const int fAlignment = 4;
160 int needed = nBytes % fAlignment == 0 ? nBytes : (nBytes/fAlignment+1)*fAlignment;
161 return needed + 2*
sizeof(int);
165 if (fStackOffset + n >= default_size) {
177 int end = fStackOffset;
179 while (beg < fStackOffset) {
185 int beg2 = ReadInt( end -
sizeof(
int));
193 if (end != fStackOffset) {
197 if (nblocks != fBlockCount) {
226 return gStackAllocator;
define stack allocator symbol
Namespace for new ROOT classes and functions.
int AlignedSize(int nBytes)
StackAllocator controls the memory allocation/deallocation of Minuit.
void CheckOverflow(int n)
void * Allocate(size_t nBytes)
static constexpr double pc
static StackAllocator & Get()
void WriteInt(int offset, int Value)