Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TStorage Class Reference

Storage manager.

The storage manager works best in conjunction with the custom ROOT new and delete operators defined in the file NewDelete.cxx (libNew.so). Only when using the custom allocation operators will memory usage statistics be gathered using the TStorage EnterStat(), RemoveStat(), etc. functions. Memory checking is by default enabled (when using libNew.so) and usage statistics is gathered. Using the resource (in .rootrc): Root.MemStat one can toggle statistics gathering on or off. More specifically on can trap the allocation of a block of memory of a certain size. This can be specified using the resource: Root.MemStat.size, using the resource Root.MemStat.cnt one can specify after how many allocations of this size the trap should occur.

Set the compile option R__NOSTATS to de-activate all memory checking and statistics gathering in the system.

Definition at line 33 of file TStorage.h.

Public Member Functions

virtual ~TStorage ()
 
virtual TClassIsA () const
 
virtual void Streamer (TBuffer &)
 
void StreamerNVirtual (TBuffer &ClassDef_StreamerNVirtual_b)
 

Static Public Member Functions

static void AddToHeap (ULong_t begin, ULong_t end)
 add a range to the heap
 
static void * Alloc (size_t size)
 Allocate a block of memory, that later can be resized using TStorage::ReAlloc().
 
static TClassClass ()
 
static const char * Class_Name ()
 
static constexpr Version_t Class_Version ()
 
static void Dealloc (void *ptr)
 De-allocate block of memory, that was allocated via TStorage::Alloc().
 
static const char * DeclFileName ()
 
static void EnableStatistics (int size=-1, int ix=-1)
 Enable memory usage statistics gathering.
 
static void EnterStat (size_t size, void *p)
 Register a memory allocation operation.
 
static Bool_t FilledByObjectAlloc (volatile const UInt_t *const member)
 
static FreeHookFun_t GetFreeHook ()
 
static void * GetFreeHookData ()
 return static free hook data
 
static ULong_t GetHeapBegin ()
 
static ULong_t GetHeapEnd ()
 
static size_t GetMaxBlockSize ()
 
static Bool_t HasCustomNewDelete ()
 return the has custom delete flag
 
static Bool_t IsOnHeap (void *p)
 is object at p in the heap?
 
static void * ObjectAlloc (size_t size)
 Used to allocate a TObject on the heap (via TObject::operator new()).
 
static void * ObjectAlloc (size_t size, void *vp)
 Used to allocate a TObject on the heap (via TObject::operator new(size_t,void*)) in position vp.
 
static void * ObjectAllocArray (size_t size)
 Used to allocate array of TObject on the heap (via TObject::operator new[]()).
 
static void ObjectDealloc (void *vp)
 Used to deallocate a TObject on the heap (via TObject::operator delete()).
 
static void ObjectDealloc (void *vp, void *ptr)
 Used to deallocate a TObject on the heap (via TObject::operator delete(void*,void*)).
 
static void PrintStatistics ()
 Print memory usage statistics.
 
static void * ReAlloc (void *vp, size_t size)
 Reallocate (i.e.
 
static void * ReAlloc (void *vp, size_t size, size_t oldsize)
 Reallocate (i.e.
 
static char * ReAllocChar (char *vp, size_t size, size_t oldsize)
 Reallocate (i.e.
 
static Int_tReAllocInt (Int_t *vp, size_t size, size_t oldsize)
 Reallocate (i.e.
 
static void RemoveStat (void *p)
 Register a memory free operation.
 
static void SetCustomNewDelete ()
 set the has custom delete flag
 
static void SetFreeHook (FreeHookFun_t func, void *data)
 Set a free handler.
 
static void SetMaxBlockSize (size_t size)
 
static void SetReAllocHooks (ReAllocFun_t func1, ReAllocCFun_t func2)
 Set a custom ReAlloc handlers.
 
static void UpdateIsOnHeap (volatile const UInt_t &uniqueID, volatile UInt_t &bits)
 

Static Public Attributes

static const UInt_t kObjectAllocMemValue = 0x99999999
 

Private Types

enum  { kIsOnHeap = 0x01000000 }
 

Static Private Attributes

static FreeHookFun_t fgFreeHook
 
static void * fgFreeHookData
 
static Bool_t fgHasCustomNewDelete
 
static size_t fgMaxBlockSize
 
static ReAllocCFun_t fgReAllocCHook
 
static ReAllocFun_t fgReAllocHook
 

#include <TStorage.h>

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
private
Enumerator
kIsOnHeap 

object is on heap

Definition at line 44 of file TStorage.h.

Constructor & Destructor Documentation

◆ ~TStorage()

virtual TStorage::~TStorage ( )
inlinevirtual

Definition at line 53 of file TStorage.h.

Member Function Documentation

◆ AddToHeap()

void TStorage::AddToHeap ( ULong_t  begin,
ULong_t  end 
)
static

add a range to the heap

Definition at line 511 of file TStorage.cxx.

◆ Alloc()

void * TStorage::Alloc ( size_t  size)
static

Allocate a block of memory, that later can be resized using TStorage::ReAlloc().

Definition at line 152 of file TStorage.cxx.

◆ Class()

static TClass * TStorage::Class ( )
static
Returns
TClass describing this class

◆ Class_Name()

static const char * TStorage::Class_Name ( )
static
Returns
Name of this class

◆ Class_Version()

static constexpr Version_t TStorage::Class_Version ( )
inlinestaticconstexpr
Returns
Version of this class

Definition at line 93 of file TStorage.h.

◆ Dealloc()

void TStorage::Dealloc ( void *  ptr)
static

De-allocate block of memory, that was allocated via TStorage::Alloc().

Definition at line 170 of file TStorage.cxx.

◆ DeclFileName()

static const char * TStorage::DeclFileName ( )
inlinestatic
Returns
Name of the file containing the class declaration

Definition at line 93 of file TStorage.h.

◆ EnableStatistics()

void TStorage::EnableStatistics ( int  size = -1,
int  ix = -1 
)
static

Enable memory usage statistics gathering.

Size is the size of the memory block that should be trapped and ix is after how many such allocations the trap should happen.

Definition at line 454 of file TStorage.cxx.

◆ EnterStat()

void TStorage::EnterStat ( size_t  size,
void *  p 
)
static

Register a memory allocation operation.

If desired one can trap an allocation of a certain size in case one tries to find a memory leak of that particular size. This function is only called via the ROOT custom new operators.

Definition at line 99 of file TStorage.cxx.

◆ FilledByObjectAlloc()

Bool_t TStorage::FilledByObjectAlloc ( volatile const UInt_t *const  member)
inlinestatic

Definition at line 96 of file TStorage.h.

◆ GetFreeHook()

FreeHookFun_t TStorage::GetFreeHook ( )
inlinestatic

Definition at line 143 of file TStorage.h.

◆ GetFreeHookData()

void * TStorage::GetFreeHookData ( )
static

return static free hook data

Definition at line 486 of file TStorage.cxx.

◆ GetHeapBegin()

ULong_t TStorage::GetHeapBegin ( )
static

Definition at line 467 of file TStorage.cxx.

◆ GetHeapEnd()

ULong_t TStorage::GetHeapEnd ( )
static

Definition at line 476 of file TStorage.cxx.

◆ GetMaxBlockSize()

size_t TStorage::GetMaxBlockSize ( )
inlinestatic

Definition at line 139 of file TStorage.h.

◆ HasCustomNewDelete()

Bool_t TStorage::HasCustomNewDelete ( )
static

return the has custom delete flag

Definition at line 494 of file TStorage.cxx.

◆ IsA()

virtual TClass * TStorage::IsA ( ) const
inlinevirtual
Returns
TClass describing current object

Definition at line 93 of file TStorage.h.

◆ IsOnHeap()

Bool_t TStorage::IsOnHeap ( void *  p)
static

is object at p in the heap?

Definition at line 519 of file TStorage.cxx.

◆ ObjectAlloc() [1/2]

void * TStorage::ObjectAlloc ( size_t  sz)
static

Used to allocate a TObject on the heap (via TObject::operator new()).

Directly after this routine one can call (in the TObject ctor) TStorage::FilledByObjectAlloc() to find out if the just created object is on the heap. This technique is necessary as there is one stack per thread and we can not rely on comparison with the current stack memory position.

Definition at line 332 of file TStorage.cxx.

◆ ObjectAlloc() [2/2]

void * TStorage::ObjectAlloc ( size_t  size,
void *  vp 
)
static

Used to allocate a TObject on the heap (via TObject::operator new(size_t,void*)) in position vp.

vp is already allocated (maybe on heap, maybe on stack) so just return.

Definition at line 355 of file TStorage.cxx.

◆ ObjectAllocArray()

void * TStorage::ObjectAllocArray ( size_t  sz)
static

Used to allocate array of TObject on the heap (via TObject::operator new[]()).

Unlike the 'singular' ObjectAlloc, we do not mark those object has being allocated on the heap as they can not be individually deleted.

Definition at line 344 of file TStorage.cxx.

◆ ObjectDealloc() [1/2]

void TStorage::ObjectDealloc ( void *  vp)
static

Used to deallocate a TObject on the heap (via TObject::operator delete()).

Definition at line 363 of file TStorage.cxx.

◆ ObjectDealloc() [2/2]

void TStorage::ObjectDealloc ( void *  vp,
void *  ptr 
)
static

Used to deallocate a TObject on the heap (via TObject::operator delete(void*,void*)).

Definition at line 372 of file TStorage.cxx.

◆ PrintStatistics()

void TStorage::PrintStatistics ( )
static

Print memory usage statistics.

Definition at line 410 of file TStorage.cxx.

◆ ReAlloc() [1/2]

void * TStorage::ReAlloc ( void *  ovp,
size_t  size 
)
static

Reallocate (i.e.

resize) block of memory. Don't use if size is larger than old size, use ReAlloc(void *, size_t, size_t) instead.

Definition at line 183 of file TStorage.cxx.

◆ ReAlloc() [2/2]

void * TStorage::ReAlloc ( void *  ovp,
size_t  size,
size_t  oldsize 
)
static

Reallocate (i.e.

resize) block of memory. Checks if current size is equal to oldsize. If not memory was overwritten.

Definition at line 224 of file TStorage.cxx.

◆ ReAllocChar()

char * TStorage::ReAllocChar ( char *  ovp,
size_t  size,
size_t  oldsize 
)
static

Reallocate (i.e.

resize) array of chars. Size and oldsize are in number of chars.

Definition at line 269 of file TStorage.cxx.

◆ ReAllocInt()

Int_t * TStorage::ReAllocInt ( Int_t ovp,
size_t  size,
size_t  oldsize 
)
static

Reallocate (i.e.

resize) array of integers. Size and oldsize are number of integers (not number of bytes).

Definition at line 299 of file TStorage.cxx.

◆ RemoveStat()

void TStorage::RemoveStat ( void *  vp)
static

Register a memory free operation.

This function is only called via the custom ROOT delete operator.

Definition at line 129 of file TStorage.cxx.

◆ SetCustomNewDelete()

void TStorage::SetCustomNewDelete ( )
static

set the has custom delete flag

Definition at line 502 of file TStorage.cxx.

◆ SetFreeHook()

void TStorage::SetFreeHook ( FreeHookFun_t  func,
void *  data 
)
static

Set a free handler.

Definition at line 391 of file TStorage.cxx.

◆ SetMaxBlockSize()

void TStorage::SetMaxBlockSize ( size_t  size)
inlinestatic

Definition at line 141 of file TStorage.h.

◆ SetReAllocHooks()

void TStorage::SetReAllocHooks ( ReAllocFun_t  rh1,
ReAllocCFun_t  rh2 
)
static

Set a custom ReAlloc handlers.

This function is typically called via a static object in the ROOT libNew.so shared library.

Definition at line 401 of file TStorage.cxx.

◆ Streamer()

virtual void TStorage::Streamer ( TBuffer )
virtual

◆ StreamerNVirtual()

void TStorage::StreamerNVirtual ( TBuffer ClassDef_StreamerNVirtual_b)
inline

Definition at line 93 of file TStorage.h.

◆ UpdateIsOnHeap()

R__NEVER_INLINE void TStorage::UpdateIsOnHeap ( volatile const UInt_t uniqueID,
volatile UInt_t bits 
)
static

Definition at line 131 of file TStorage.h.

Member Data Documentation

◆ fgFreeHook

FreeHookFun_t TStorage::fgFreeHook
staticprivate

Definition at line 37 of file TStorage.h.

◆ fgFreeHookData

void * TStorage::fgFreeHookData
staticprivate

Definition at line 38 of file TStorage.h.

◆ fgHasCustomNewDelete

Bool_t TStorage::fgHasCustomNewDelete
staticprivate

Definition at line 41 of file TStorage.h.

◆ fgMaxBlockSize

size_t TStorage::fgMaxBlockSize
staticprivate

Definition at line 36 of file TStorage.h.

◆ fgReAllocCHook

ReAllocCFun_t TStorage::fgReAllocCHook
staticprivate

Definition at line 40 of file TStorage.h.

◆ fgReAllocHook

ReAllocFun_t TStorage::fgReAllocHook
staticprivate

Definition at line 39 of file TStorage.h.

◆ kObjectAllocMemValue

const UInt_t TStorage::kObjectAllocMemValue = 0x99999999
static

Definition at line 49 of file TStorage.h.

  • core/base/inc/TStorage.h
  • core/base/src/TStorage.cxx