41 #if !defined(R__NOSTATS)
44 # define MEM_CHECKOBJECTPOINTERS
47 #if defined(MEM_STAT) && !defined(MEM_DEBUG)
53 # define storage_size(p) ((size_t)(((size_t*)p)[-1]))
55 # define storage_size(p) ((size_t)(((int*)p)[-2]))
58 # define storage_size(p) ((size_t)0)
75 static const
char *gSpaceErr = "storage exhausted";
97 if (!gMemStatistics)
return;
106 if (gTraceIndex >= gTraceCapacity) {
107 gTraceCapacity = gTraceCapacity*2;
108 gTraceArray = (
void**) realloc(gTraceArray,
sizeof(
void*)*
gTraceCapacity);
110 gTraceArray[gTraceIndex++] = p;
112 if (size >= kObjMaxSize)
116 gAllocatedTotal += size;
148 static const char *where =
"TStorage::Alloc";
151 void *vp = ::operator
new[](size);
153 void *vp = ::operator
new(size);
156 Fatal(where,
"%s", gSpaceErr);
167 ::operator
delete[](ptr);
169 ::operator
delete(ptr);
179 ::Obsolete(
"ReAlloc(void*,size_t)",
"v5-34-00",
"v6-02-00");
180 ::Info(
"ReAlloc(void*,size_t)",
"please use ReAlloc(void*,size_t,size_t)");
190 static const char *where =
"TStorage::ReAlloc";
193 void *vp = ::operator
new[](size);
195 void *vp = ::operator
new(size);
198 Fatal(where,
"%s", gSpaceErr);
203 memmove(vp, ovp, size);
205 ::operator
delete[](ovp);
207 ::operator
delete(ovp);
226 static const char *where =
"TStorage::ReAlloc";
232 void *vp = ::operator
new[](size);
234 void *vp = ::operator
new(size);
237 Fatal(where,
"%s", gSpaceErr);
242 if (size > oldsize) {
243 memcpy(vp, ovp, oldsize);
244 memset((
char*)vp+oldsize, 0, size-oldsize);
246 memcpy(vp, ovp, size);
248 ::operator
delete[](ovp);
250 ::operator
delete(ovp);
261 static const char *where =
"TStorage::ReAllocChar";
267 Fatal(where,
"%s", gSpaceErr);
275 Fatal(where,
"%s", gSpaceErr);
276 if (size > oldsize) {
277 memcpy(vp, ovp, oldsize);
278 memset((
char*)vp+oldsize, 0, size-oldsize);
280 memcpy(vp, ovp, size);
291 static const char *where =
"TStorage::ReAllocInt";
295 vp =
new Int_t[size];
297 Fatal(where,
"%s", gSpaceErr);
303 vp =
new Int_t[size];
305 Fatal(where,
"%s", gSpaceErr);
306 if (size > oldsize) {
307 memcpy(vp, ovp, oldsize*
sizeof(
Int_t));
308 memset((
Int_t*)vp+oldsize, 0, (size-oldsize)*
sizeof(
Int_t));
310 memcpy(vp, ovp, size*
sizeof(
Int_t));
324 void* space = ::operator
new(sz);
336 void* space = ::operator
new(sz);
356 ::operator
delete(vp);
394 #if defined(MEM_DEBUG) && defined(MEM_STAT)
400 Printf(
"Heap statistics");
401 Printf(
"%12s%12s%12s%12s",
"size",
"alloc",
"free",
"diff");
402 Printf(
"================================================");
412 Printf(
"------------------------------------------------");
418 Printf(
"------------------------------------------------");
423 Printf(
"================================================");
440 int idum = size;
int iidum = ix;
448 ::Obsolete(
"GetHeapBegin()",
"v5-34-00",
"v6-02-00");
457 ::Obsolete(
"GetHeapBegin()",
"v5-34-00",
"v6-02-00");
492 ::Obsolete(
"AddToHeap(ULong_t,ULong_t)",
"v5-34-00",
"v6-02-00");
500 ::Obsolete(
"IsOnHeap(void*)",
"v5-34-00",
"v6-02-00");
static void Dealloc(void *ptr)
De-allocate block of memory, that was allocated via TStorage::Alloc().
void *(* ReAllocFun_t)(void *, size_t)
void Fatal(const char *location, const char *msgfmt,...)
static const UInt_t kObjectAllocMemValue
static ULong_t GetHeapBegin()
static Bool_t MemCheck()
Return kTRUE if the memory leak checker is on.
static void * ObjectAlloc(size_t size)
Used to allocate a TObject on the heap (via TObject::operator new()).
static ULong_t GetHeapEnd()
void Obsolete(const char *function, const char *asOfVers, const char *removedFromVers)
Use this function to declare a function obsolete.
static ReAllocCFun_t fgReAllocCHook
static void AddToHeap(ULong_t begin, ULong_t end)
add a range to the heap
static char * ReAllocChar(char *vp, size_t size, size_t oldsize)
Reallocate (i.e.
static void * fgFreeHookData
void Info(const char *location, const char *msgfmt,...)
static Bool_t fgHasCustomNewDelete
static size_t GetMaxBlockSize()
R__EXTERN TVirtualMutex * gGlobalMutex
static Bool_t gMemStatistics
static void * GetFreeHookData()
return static free hook data
static FreeHookFun_t GetFreeHook()
static void EnableStatistics(int size=-1, int ix=-1)
Enable memory usage statistics gathering.
static Bool_t HasCustomNewDelete()
return the has custom delete flag
static void SetCustomNewDelete()
set the has custom delete flag
static Int_t gAllocatedTotal
static FreeHookFun_t fgFreeHook
static void SetReAllocHooks(ReAllocFun_t func1, ReAllocCFun_t func2)
Set a custom ReAlloc handlers.
static void * Alloc(size_t size)
Allocate a block of memory, that later can be resized using TStorage::ReAlloc().
ClassImp(TStorage) static const char *gSpaceErr
static Int_t gAllocated[kObjMaxSize]
static void SetFreeHook(FreeHookFun_t func, void *data)
Set a free handler.
static Bool_t IsOnHeap(void *p)
is object at p in the heap?
void *(* ReAllocCFun_t)(void *, size_t, size_t)
#define R__LOCKGUARD(mutex)
static Int_t gFreed[kObjMaxSize]
static void * ReAlloc(void *vp, size_t size)
Reallocate (i.e.
void(* FreeHookFun_t)(void *, void *addr, size_t)
static void RemoveStat(void *p)
Register a memory free operation.
Short_t Max(Short_t a, Short_t b)
static void SetMaxBlockSize(size_t size)
static Int_t gTraceCapacity
static void * ObjectAllocArray(size_t size)
Used to allocate array of TObject on the heap (via TObject::operator new[]()).
static Bool_t FilledByObjectAlloc(UInt_t *member)
static void ** gTraceArray
static ReAllocFun_t fgReAllocHook
Vc_ALWAYS_INLINE_L T *Vc_ALWAYS_INLINE_R malloc(size_t n)
Allocates memory on the Heap with alignment and padding suitable for vectorized access.
static size_t fgMaxBlockSize
static void ObjectDealloc(void *vp)
Used to deallocate a TObject on the heap (via TObject::operator delete()).
static void PrintStatistics()
Print memory usage statistics.
static Int_t * ReAllocInt(Int_t *vp, size_t size, size_t oldsize)
Reallocate (i.e.