19static malloc_zone_t original_zone;
21static void* profile_malloc(malloc_zone_t *zone,
size_t size);
22static void* profile_calloc(malloc_zone_t *zone,
size_t num_items,
size_t size);
23static void* profile_valloc(malloc_zone_t *zone,
size_t size);
24static void profile_free(malloc_zone_t *zone,
void *ptr);
25#if defined(MAC_OS_X_VERSION_10_6)
26static void profile_free_definite_size(malloc_zone_t *zone,
void *ptr,
size_t size);
30static zoneMallocHookFunc_t m_pm;
31static zoneFreeHookFunc_t m_pf;
36#if defined(R__GNU) && (defined(R__LINUX) || defined(__APPLE__))
37#define SUPPORTS_MEMSTAT
43#if !defined(__APPLE__)
50#if defined(SUPPORTS_MEMSTAT)
63#if defined(SUPPORTS_MEMSTAT)
76#if defined(SUPPORTS_MEMSTAT)
87#if defined(SUPPORTS_MEMSTAT)
97#if defined (__APPLE__)
98void TMemStatHook::trackZoneMalloc(zoneMallocHookFunc_t pm,
99 zoneFreeHookFunc_t pf)
101 malloc_zone_t* zone = malloc_default_zone();
103 cerr <<
"Error: Can't get malloc_default_zone" << endl;
109 original_zone = *zone;
110 zone->malloc = &profile_malloc;
111 zone->calloc = &profile_calloc;
112 zone->valloc = &profile_valloc;
113 zone->free = &profile_free;
114#if defined(MAC_OS_X_VERSION_10_6)
115 if (zone->version >= 6 && zone->free_definite_size)
116 zone->free_definite_size = &profile_free_definite_size;
123void TMemStatHook::untrackZoneMalloc()
125 malloc_zone_t* zone = malloc_default_zone();
127 cerr <<
"Error: Can't get malloc_default_zone" << endl;
130 *zone = original_zone;
135void* profile_malloc(malloc_zone_t *zone,
size_t size)
137 void* ptr = (*original_zone.malloc)(zone, size);
145void* profile_calloc(malloc_zone_t *zone,
size_t num_items,
size_t size)
147 void* ptr = (*original_zone.calloc)(zone, num_items, size);
155void* profile_valloc(malloc_zone_t *zone,
size_t size)
157 void* ptr = (*original_zone.valloc)(zone, size);
165void profile_free(malloc_zone_t *zone,
void *ptr)
167 (*original_zone.free)(zone, ptr);
174#if defined(MAC_OS_X_VERSION_10_6)
175void profile_free_definite_size(malloc_zone_t *zone,
void *ptr,
size_t size)
177 (*original_zone.free_definite_size)(zone, ptr, size);
static MallocHookFunc_t GetMallocHook()
GetMallocHook - a static function malloc function getter.
static void SetMallocHook(MallocHookFunc_t p)
SetMallocHook - a static function Set pointer to function replacing alloc function.
void(* FreeHookFunc_t)(void *ptr, const void *caller)
void *(* MallocHookFunc_t)(size_t size, const void *caller)
static FreeHookFunc_t GetFreeHook()
GetFreeHook - a static function free function getter.
static void SetFreeHook(FreeHookFunc_t p)
SetFreeHook - a static function Set pointer to function replacing free function.