1 // @(#)root/base:$Id$ 2 // Author: Fons Rademakers 29/07/95 3 4 /************************************************************************* 5 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. * 6 * All rights reserved. * 7 * * 8 * For the licensing terms see $ROOTSYS/LICENSE. * 9 * For the list of contributors see $ROOTSYS/README/CREDITS. * 10 *************************************************************************/ 11 12 #ifndef ROOT_TStorage 13 #define ROOT_TStorage 14 15 16 ////////////////////////////////////////////////////////////////////////// 17 // // 18 // TStorage // 19 // // 20 // Storage manager. // 21 // // 22 ////////////////////////////////////////////////////////////////////////// 23 24 #ifndef ROOT_Rtypes 25 #include "Rtypes.h" 26 #endif 27 28 typedef void (*FreeHookFun_t)(void*, void *addr, size_t); 29 typedef void *(*ReAllocFun_t)(void*, size_t); 30 typedef void *(*ReAllocCFun_t)(void*, size_t, size_t); 31 typedef char *(*ReAllocCharFun_t)(char*, size_t, size_t); 32 33 34 class TStorage { 35 36 private: 37 static size_t fgMaxBlockSize; // largest block allocated 38 static FreeHookFun_t fgFreeHook; // function called on free 39 static void *fgFreeHookData; // data used by this function 40 static ReAllocFun_t fgReAllocHook; // custom ReAlloc 41 static ReAllocCFun_t fgReAllocCHook; // custom ReAlloc with length check 42 static Bool_t fgHasCustomNewDelete; // true if using ROOT's new/delete 43 static const UInt_t kObjectAllocMemValue = 0x99999999; 44 // magic number for ObjectAlloc 45 46 public: 47 virtual ~TStorage() { } 48 49 static ULong_t GetHeapBegin(); 50 static ULong_t GetHeapEnd(); 51 static FreeHookFun_t GetFreeHook(); 52 static void *GetFreeHookData(); 53 static size_t GetMaxBlockSize(); 54 static void *Alloc(size_t size); 55 static void Dealloc(void *ptr); 56 static void *ReAlloc(void *vp, size_t size); 57 static void *ReAlloc(void *vp, size_t size, size_t oldsize); 58 static char *ReAllocChar(char *vp, size_t size, size_t oldsize); 59 static Int_t *ReAllocInt(Int_t *vp, size_t size, size_t oldsize); 60 static void *ObjectAlloc(size_t size); 61 static void *ObjectAlloc(size_t size, void *vp); 62 static void ObjectDealloc(void *vp); 63 static void ObjectDealloc(void *vp, void *ptr); 64 65 static void EnterStat(size_t size, void *p); 66 static void RemoveStat(void *p); 67 static void PrintStatistics(); 68 static void SetMaxBlockSize(size_t size); 69 static void SetFreeHook(FreeHookFun_t func, void *data); 70 static void SetReAllocHooks(ReAllocFun_t func1, ReAllocCFun_t func2); 71 static void SetCustomNewDelete(); 72 static void EnableStatistics(int size= -1, int ix= -1); 73 74 static Bool_t HasCustomNewDelete(); 75 76 // only valid after call to a TStorage allocating method 77 static void AddToHeap(ULong_t begin, ULong_t end); 78 static Bool_t IsOnHeap(void *p); 79 80 static Bool_t FilledByObjectAlloc(UInt_t* member); 81 82 ClassDef(TStorage,0) //Storage manager class 83 }; 84 85 #ifndef WIN32 86 inline Bool_t TStorage::FilledByObjectAlloc(UInt_t *member) { return *member == kObjectAllocMemValue; } 87 88 inline size_t TStorage::GetMaxBlockSize() { return fgMaxBlockSize; } 89 90 inline void TStorage::SetMaxBlockSize(size_t size) { fgMaxBlockSize = size; } 91 92 inline FreeHookFun_t TStorage::GetFreeHook() { return fgFreeHook; } 93 #endif 94 95 #endif 96