ROOT logo
// @(#)root/base:$Id: TStorage.h 27683 2009-03-03 20:15:49Z pcanal $
// Author: Fons Rademakers   29/07/95

/*************************************************************************
 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#ifndef ROOT_TStorage
#define ROOT_TStorage


//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TStorage                                                             //
//                                                                      //
// Storage manager.                                                     //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#ifndef ROOT_Rtypes
#include "Rtypes.h"
#endif

typedef void (*FreeHookFun_t)(void*, void *addr, size_t);
typedef void *(*ReAllocFun_t)(void*, size_t);
typedef void *(*ReAllocCFun_t)(void*, size_t, size_t);
typedef char *(*ReAllocCharFun_t)(char*, size_t, size_t);


class TStorage {

private:
   static ULong_t        fgHeapBegin;          // begin address of heap
   static ULong_t        fgHeapEnd;            // end address of heap
   static size_t         fgMaxBlockSize;       // largest block allocated
   static FreeHookFun_t  fgFreeHook;           // function called on free
   static void          *fgFreeHookData;       // data used by this function
   static ReAllocFun_t   fgReAllocHook;        // custom ReAlloc
   static ReAllocCFun_t  fgReAllocCHook;       // custom ReAlloc with length check
   static Bool_t         fgHasCustomNewDelete; // true if using ROOT's new/delete

public:
   virtual ~TStorage() { }

   static ULong_t        GetHeapBegin();
   static ULong_t        GetHeapEnd();
   static FreeHookFun_t  GetFreeHook();
   static void          *GetFreeHookData();
   static size_t         GetMaxBlockSize();
   static void          *Alloc(size_t size);
   static void           Dealloc(void *ptr);
   static void          *ReAlloc(void *vp, size_t size);
   static void          *ReAlloc(void *vp, size_t size, size_t oldsize);
   static char          *ReAllocChar(char *vp, size_t size, size_t oldsize);
   static Int_t         *ReAllocInt(Int_t *vp, size_t size, size_t oldsize);
   static void          *ObjectAlloc(size_t size);
   static void          *ObjectAlloc(size_t size, void *vp);
   static void           ObjectDealloc(void *vp);
   static void           ObjectDealloc(void *vp, void *ptr);

   static void EnterStat(size_t size, void *p);
   static void RemoveStat(void *p);
   static void PrintStatistics();
   static void SetMaxBlockSize(size_t size);
   static void SetFreeHook(FreeHookFun_t func, void *data);
   static void SetReAllocHooks(ReAllocFun_t func1, ReAllocCFun_t func2);
   static void SetCustomNewDelete();
   static void EnableStatistics(int size= -1, int ix= -1);

   static Bool_t HasCustomNewDelete();

   // only valid after call to a TStorage allocating method
   static void   AddToHeap(ULong_t begin, ULong_t end);
   static Bool_t IsOnHeap(void *p);

   ClassDef(TStorage,0)  //Storage manager class
};

#ifndef WIN32
inline void TStorage::AddToHeap(ULong_t begin, ULong_t end)
   { if (begin < fgHeapBegin) fgHeapBegin = begin;
     if (end   > fgHeapEnd)   fgHeapEnd   = end; }

inline Bool_t TStorage::IsOnHeap(void *p)
   { return (ULong_t)p >= fgHeapBegin && (ULong_t)p < fgHeapEnd; }

inline size_t TStorage::GetMaxBlockSize() { return fgMaxBlockSize; }

inline void TStorage::SetMaxBlockSize(size_t size) { fgMaxBlockSize = size; }

inline FreeHookFun_t TStorage::GetFreeHook() { return fgFreeHook; }
#endif

#endif
 TStorage.h:1
 TStorage.h:2
 TStorage.h:3
 TStorage.h:4
 TStorage.h:5
 TStorage.h:6
 TStorage.h:7
 TStorage.h:8
 TStorage.h:9
 TStorage.h:10
 TStorage.h:11
 TStorage.h:12
 TStorage.h:13
 TStorage.h:14
 TStorage.h:15
 TStorage.h:16
 TStorage.h:17
 TStorage.h:18
 TStorage.h:19
 TStorage.h:20
 TStorage.h:21
 TStorage.h:22
 TStorage.h:23
 TStorage.h:24
 TStorage.h:25
 TStorage.h:26
 TStorage.h:27
 TStorage.h:28
 TStorage.h:29
 TStorage.h:30
 TStorage.h:31
 TStorage.h:32
 TStorage.h:33
 TStorage.h:34
 TStorage.h:35
 TStorage.h:36
 TStorage.h:37
 TStorage.h:38
 TStorage.h:39
 TStorage.h:40
 TStorage.h:41
 TStorage.h:42
 TStorage.h:43
 TStorage.h:44
 TStorage.h:45
 TStorage.h:46
 TStorage.h:47
 TStorage.h:48
 TStorage.h:49
 TStorage.h:50
 TStorage.h:51
 TStorage.h:52
 TStorage.h:53
 TStorage.h:54
 TStorage.h:55
 TStorage.h:56
 TStorage.h:57
 TStorage.h:58
 TStorage.h:59
 TStorage.h:60
 TStorage.h:61
 TStorage.h:62
 TStorage.h:63
 TStorage.h:64
 TStorage.h:65
 TStorage.h:66
 TStorage.h:67
 TStorage.h:68
 TStorage.h:69
 TStorage.h:70
 TStorage.h:71
 TStorage.h:72
 TStorage.h:73
 TStorage.h:74
 TStorage.h:75
 TStorage.h:76
 TStorage.h:77
 TStorage.h:78
 TStorage.h:79
 TStorage.h:80
 TStorage.h:81
 TStorage.h:82
 TStorage.h:83
 TStorage.h:84
 TStorage.h:85
 TStorage.h:86
 TStorage.h:87
 TStorage.h:88
 TStorage.h:89
 TStorage.h:90
 TStorage.h:91
 TStorage.h:92
 TStorage.h:93
 TStorage.h:94
 TStorage.h:95
 TStorage.h:96
 TStorage.h:97
 TStorage.h:98