TStorage.h

Go to the documentation of this file.
00001 // @(#)root/base:$Id: TStorage.h 27683 2009-03-03 20:15:49Z pcanal $
00002 // Author: Fons Rademakers   29/07/95
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 #ifndef ROOT_TStorage
00013 #define ROOT_TStorage
00014 
00015 
00016 //////////////////////////////////////////////////////////////////////////
00017 //                                                                      //
00018 // TStorage                                                             //
00019 //                                                                      //
00020 // Storage manager.                                                     //
00021 //                                                                      //
00022 //////////////////////////////////////////////////////////////////////////
00023 
00024 #ifndef ROOT_Rtypes
00025 #include "Rtypes.h"
00026 #endif
00027 
00028 typedef void (*FreeHookFun_t)(void*, void *addr, size_t);
00029 typedef void *(*ReAllocFun_t)(void*, size_t);
00030 typedef void *(*ReAllocCFun_t)(void*, size_t, size_t);
00031 typedef char *(*ReAllocCharFun_t)(char*, size_t, size_t);
00032 
00033 
00034 class TStorage {
00035 
00036 private:
00037    static ULong_t        fgHeapBegin;          // begin address of heap
00038    static ULong_t        fgHeapEnd;            // end address of heap
00039    static size_t         fgMaxBlockSize;       // largest block allocated
00040    static FreeHookFun_t  fgFreeHook;           // function called on free
00041    static void          *fgFreeHookData;       // data used by this function
00042    static ReAllocFun_t   fgReAllocHook;        // custom ReAlloc
00043    static ReAllocCFun_t  fgReAllocCHook;       // custom ReAlloc with length check
00044    static Bool_t         fgHasCustomNewDelete; // true if using ROOT's new/delete
00045 
00046 public:
00047    virtual ~TStorage() { }
00048 
00049    static ULong_t        GetHeapBegin();
00050    static ULong_t        GetHeapEnd();
00051    static FreeHookFun_t  GetFreeHook();
00052    static void          *GetFreeHookData();
00053    static size_t         GetMaxBlockSize();
00054    static void          *Alloc(size_t size);
00055    static void           Dealloc(void *ptr);
00056    static void          *ReAlloc(void *vp, size_t size);
00057    static void          *ReAlloc(void *vp, size_t size, size_t oldsize);
00058    static char          *ReAllocChar(char *vp, size_t size, size_t oldsize);
00059    static Int_t         *ReAllocInt(Int_t *vp, size_t size, size_t oldsize);
00060    static void          *ObjectAlloc(size_t size);
00061    static void          *ObjectAlloc(size_t size, void *vp);
00062    static void           ObjectDealloc(void *vp);
00063    static void           ObjectDealloc(void *vp, void *ptr);
00064 
00065    static void EnterStat(size_t size, void *p);
00066    static void RemoveStat(void *p);
00067    static void PrintStatistics();
00068    static void SetMaxBlockSize(size_t size);
00069    static void SetFreeHook(FreeHookFun_t func, void *data);
00070    static void SetReAllocHooks(ReAllocFun_t func1, ReAllocCFun_t func2);
00071    static void SetCustomNewDelete();
00072    static void EnableStatistics(int size= -1, int ix= -1);
00073 
00074    static Bool_t HasCustomNewDelete();
00075 
00076    // only valid after call to a TStorage allocating method
00077    static void   AddToHeap(ULong_t begin, ULong_t end);
00078    static Bool_t IsOnHeap(void *p);
00079 
00080    ClassDef(TStorage,0)  //Storage manager class
00081 };
00082 
00083 #ifndef WIN32
00084 inline void TStorage::AddToHeap(ULong_t begin, ULong_t end)
00085    { if (begin < fgHeapBegin) fgHeapBegin = begin;
00086      if (end   > fgHeapEnd)   fgHeapEnd   = end; }
00087 
00088 inline Bool_t TStorage::IsOnHeap(void *p)
00089    { return (ULong_t)p >= fgHeapBegin && (ULong_t)p < fgHeapEnd; }
00090 
00091 inline size_t TStorage::GetMaxBlockSize() { return fgMaxBlockSize; }
00092 
00093 inline void TStorage::SetMaxBlockSize(size_t size) { fgMaxBlockSize = size; }
00094 
00095 inline FreeHookFun_t TStorage::GetFreeHook() { return fgFreeHook; }
00096 #endif
00097 
00098 #endif

Generated on Tue Jul 5 14:10:30 2011 for ROOT_528-00b_version by  doxygen 1.5.1