Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TStorage.h
Go to the documentation of this file.
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// #include "RConfigure.h" // included via Rtypes.h
25#include "Rtypes.h"
26
27typedef void (*FreeHookFun_t)(void*, void *addr, size_t);
28typedef void *(*ReAllocFun_t)(void*, size_t);
29typedef void *(*ReAllocCFun_t)(void*, size_t, size_t);
30typedef char *(*ReAllocCharFun_t)(char*, size_t, size_t);
31
32
33class TStorage {
34
35private:
36 static size_t fgMaxBlockSize; // largest block allocated
37 static FreeHookFun_t fgFreeHook; // function called on free
38 static void *fgFreeHookData; // data used by this function
39 static ReAllocCFun_t fgReAllocCHook; // custom ReAlloc with length check
40 static Bool_t fgHasCustomNewDelete; // true if using ROOT's new/delete
41
42 //----- Private bits, clients can only test but not change them
43 enum {
44 kIsOnHeap = 0x01000000, ///< object is on heap
45 };
46
47public:
48 static const UInt_t kObjectAllocMemValue = 0x99999999;
49 // magic number for ObjectAlloc
50
51public:
52 virtual ~TStorage() { }
53
55 static void *GetFreeHookData();
56 static size_t GetMaxBlockSize();
57 static void *Alloc(size_t size);
58 static void Dealloc(void *ptr);
59 static void *ReAlloc(void *vp, size_t size, size_t oldsize);
60 static char *ReAllocChar(char *vp, size_t size, size_t oldsize);
61 static Int_t *ReAllocInt(Int_t *vp, size_t size, size_t oldsize);
62 static void *ObjectAlloc(size_t size);
63 static void *ObjectAllocArray(size_t size);
64 static void *ObjectAlloc(size_t size, void *vp);
65 static void ObjectDealloc(void *vp);
66#ifdef R__SIZEDDELETE
67 static void ObjectDealloc(void *vp, size_t size);
68#endif
69 static void ObjectDealloc(void *vp, void *ptr);
70
71 static void EnterStat(size_t size, void *p);
72 static void RemoveStat(void *p);
73 static void PrintStatistics();
74 static void SetMaxBlockSize(size_t size);
75 static void SetFreeHook(FreeHookFun_t func, void *data);
76 static void SetReAllocHooks(ReAllocFun_t func1, ReAllocCFun_t func2);
77 static void SetCustomNewDelete();
78 static void EnableStatistics(int size= -1, int ix= -1);
79
81
82 static Bool_t FilledByObjectAlloc(volatile const UInt_t* const member);
83 static void UpdateIsOnHeap(volatile const UInt_t &uniqueID, volatile UInt_t &bits);
84
85 ClassDef(TStorage,0) //Storage manager class
86};
87
88inline Bool_t TStorage::FilledByObjectAlloc(volatile const UInt_t *const member) {
89 //called by TObject's constructor to determine if object was created by call to new
90
91 // This technique is necessary as there is one stack per thread
92 // and we can not rely on comparison with the current stack memory position.
93 // Note that a false positive (this routine returning true for an object
94 // created on the stack) requires the previous stack value to have been
95 // set to exactly kObjectAllocMemValue at exactly the right position (i.e.
96 // where this object's fUniqueID is located.
97 // The consequence of a false positive will be visible if and only if
98 // the object is auto-added to a TDirectory (i.e. TTree, TH*, TGraph,
99 // TEventList) or explicitly added to the directory by the user
100 // and
101 // the TDirectory (or TFile) object is created on the stack *before*
102 // the object.
103 // The consequence would be that those objects would be deleted twice, once
104 // by the TDirectory and once automatically when going out of scope
105 // (and thus quite visible). A false negative (which is not possible with
106 // this implementation) would have been a silent memory leak.
107
108 // This will be reported by valgrind as uninitialized memory reads for
109 // object created on the stack, use $ROOTSYS/etc/valgrind-root.supp
111 return *member == kObjectAllocMemValue; // NOLINT
113}
114
115// Assign the kIsOnHeap bit in 'bits' based on the pattern seen in uniqueID.
116// See Storage::FilledByObjectAlloc for details.
117// This routine is marked as inline with attribute noinline so that it never
118// inlined and thus can be used in a valgrind suppression file to suppress
119// the known/intentional uninitialized memory read but still be a 'quick'
120// function call to avoid losing performance at object creation.
121// Moving the function into the source file, results in doubling of the
122// overhead (compared to inlining)
123R__NEVER_INLINE void TStorage::UpdateIsOnHeap(volatile const UInt_t &uniqueID, volatile UInt_t &bits) {
124 if (TStorage::FilledByObjectAlloc(&uniqueID))
125 bits = bits | kIsOnHeap;
126 else
127 bits = bits & ~kIsOnHeap;
128}
129
130
131inline size_t TStorage::GetMaxBlockSize() { return fgMaxBlockSize; }
132
134
136
137namespace ROOT {
138namespace Internal {
139using FreeIfTMapFile_t = bool(void*);
140using GetMapFileMapllocDesc_t = void *(void*);
144}
145}
146
147#endif
#define R__EXTERN
Definition DllImport.h:26
#define R__INTENTIONALLY_UNINIT_END
Definition RConfig.hxx:550
#define R__NEVER_INLINE
Definition RConfig.hxx:572
#define R__INTENTIONALLY_UNINIT_BEGIN
Definition RConfig.hxx:549
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
bool Bool_t
Definition RtypesCore.h:63
int Int_t
Definition RtypesCore.h:45
unsigned int UInt_t
Definition RtypesCore.h:46
#define ClassDef(name, id)
Definition Rtypes.h:342
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
void *(* ReAllocCFun_t)(void *, size_t, size_t)
Definition TStorage.h:29
void *(* ReAllocFun_t)(void *, size_t)
Definition TStorage.h:28
void(* FreeHookFun_t)(void *, void *addr, size_t)
Definition TStorage.h:27
Storage manager.
Definition TStorage.h:33
static ReAllocCFun_t fgReAllocCHook
Definition TStorage.h:39
static void RemoveStat(void *p)
Register a memory free operation.
Definition TStorage.cxx:129
static void * Alloc(size_t size)
Allocate a block of memory, that later can be resized using TStorage::ReAlloc().
Definition TStorage.cxx:152
static Bool_t fgHasCustomNewDelete
Definition TStorage.h:40
static char * ReAllocChar(char *vp, size_t size, size_t oldsize)
Reallocate (i.e.
Definition TStorage.cxx:228
static FreeHookFun_t fgFreeHook
Definition TStorage.h:37
static Bool_t HasCustomNewDelete()
return the has custom delete flag
Definition TStorage.cxx:434
static void EnterStat(size_t size, void *p)
Register a memory allocation operation.
Definition TStorage.cxx:99
@ kIsOnHeap
object is on heap
Definition TStorage.h:44
static void ObjectDealloc(void *vp)
Used to deallocate a TObject on the heap (via TObject::operator delete()).
Definition TStorage.cxx:322
static void SetFreeHook(FreeHookFun_t func, void *data)
Set a free handler.
Definition TStorage.cxx:350
static void SetCustomNewDelete()
set the has custom delete flag
Definition TStorage.cxx:442
static void * GetFreeHookData()
return static free hook data
Definition TStorage.cxx:426
static void SetMaxBlockSize(size_t size)
Definition TStorage.h:133
static void * fgFreeHookData
Definition TStorage.h:38
static const UInt_t kObjectAllocMemValue
Definition TStorage.h:48
static void UpdateIsOnHeap(volatile const UInt_t &uniqueID, volatile UInt_t &bits)
Definition TStorage.h:123
static void Dealloc(void *ptr)
De-allocate block of memory, that was allocated via TStorage::Alloc().
Definition TStorage.cxx:170
static size_t fgMaxBlockSize
Definition TStorage.h:36
static Int_t * ReAllocInt(Int_t *vp, size_t size, size_t oldsize)
Reallocate (i.e.
Definition TStorage.cxx:258
static void SetReAllocHooks(ReAllocFun_t func1, ReAllocCFun_t func2)
Set a custom ReAlloc handlers.
Definition TStorage.cxx:360
static void * ObjectAllocArray(size_t size)
Used to allocate array of TObject on the heap (via TObject::operator new[]()).
Definition TStorage.cxx:303
static Bool_t FilledByObjectAlloc(volatile const UInt_t *const member)
Definition TStorage.h:88
virtual ~TStorage()
Definition TStorage.h:52
static void EnableStatistics(int size=-1, int ix=-1)
Enable memory usage statistics gathering.
Definition TStorage.cxx:412
static size_t GetMaxBlockSize()
Definition TStorage.h:131
static void * ReAlloc(void *vp, size_t size, size_t oldsize)
Reallocate (i.e.
Definition TStorage.cxx:183
static void * ObjectAlloc(size_t size)
Used to allocate a TObject on the heap (via TObject::operator new()).
Definition TStorage.cxx:291
static void PrintStatistics()
Print memory usage statistics.
Definition TStorage.cxx:368
static FreeHookFun_t GetFreeHook()
Definition TStorage.h:135
R__EXTERN GetMapFileMapllocDesc_t * gGetMapFileMallocDesc
Definition TStorage.h:142
void *(void *) GetMapFileMapllocDesc_t
Definition TStorage.h:140
R__EXTERN FreeIfTMapFile_t * gFreeIfTMapFile
Definition TStorage.h:141
R__EXTERN void * gMmallocDesc
Definition TStorage.h:143
bool(void *) FreeIfTMapFile_t
Definition TStorage.h:139
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...