18 #if defined(__APPLE__) 19 static malloc_zone_t original_zone;
21 static void* profile_malloc(malloc_zone_t *zone,
size_t size);
22 static void* profile_calloc(malloc_zone_t *zone,
size_t num_items,
size_t size);
23 static void* profile_valloc(malloc_zone_t *zone,
size_t size);
24 static void profile_free(malloc_zone_t *zone,
void *ptr);
25 #if defined(MAC_OS_X_VERSION_10_6) 26 static void profile_free_definite_size(malloc_zone_t *zone,
void *ptr,
size_t size);
30 static zoneMallocHookFunc_t m_pm;
31 static 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) 91 #endif // !defined(__APPLE__) 97 #if defined (__APPLE__) 98 void 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;
123 void TMemStatHook::untrackZoneMalloc()
125 malloc_zone_t* zone = malloc_default_zone();
127 cerr <<
"Error: Can't get malloc_default_zone" << endl;
130 *zone = original_zone;
135 void* profile_malloc(malloc_zone_t *zone,
size_t size)
137 void* ptr = (*original_zone.malloc)(zone, size);
145 void* profile_calloc(malloc_zone_t *zone,
size_t num_items,
size_t size)
147 void* ptr = (*original_zone.calloc)(zone, num_items, size);
155 void* profile_valloc(malloc_zone_t *zone,
size_t size)
157 void* ptr = (*original_zone.valloc)(zone, size);
165 void profile_free(malloc_zone_t *zone,
void *ptr)
167 (*original_zone.free)(zone, ptr);
174 #if defined(MAC_OS_X_VERSION_10_6) 175 void profile_free_definite_size(malloc_zone_t *zone,
void *ptr,
size_t size)
177 (*original_zone.free_definite_size)(zone, ptr, size);
180 #endif // defined(MAC_OS_X_VERSION_10_6) 181 #endif // defined(__APPLE__)
static void SetFreeHook(FreeHookFunc_t p)
SetFreeHook - a static function Set pointer to function replacing free function.
static void SetMallocHook(MallocHookFunc_t p)
SetMallocHook - a static function Set pointer to function replacing alloc function.
void *(* MallocHookFunc_t)(size_t size, const void *caller)
static FreeHookFunc_t GetFreeHook()
GetFreeHook - a static function free function getter.
void(* FreeHookFunc_t)(void *ptr, const void *caller)
static MallocHookFunc_t GetMallocHook()
GetMallocHook - a static function malloc function getter.