1 /***************************************************************************
2 * Installs handlers for malloc(), realloc() and free() *
4 * Copyright (C) 2006 by Niko Välimäki *
7 * This program is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. *
12 * This program is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
17 * You should have received a copy of the GNU General Public License *
18 * along with this program; if not, write to the *
19 * Free Software Foundation, Inc., *
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
21 ***************************************************************************/
23 #ifndef _HEAPPROFILER_H_
24 #define _HEAPPROFILER_H_
30 //#define DEBUG_HEAPPROFILER
32 typedef std::map<void *, unsigned long> AllocatedBlocks;
37 static unsigned long GetMaxHeapConsumption();
38 static unsigned long GetHeapConsumption();
40 // Prototypes for hooks
41 static void InitHooks(void);
42 static void *MallocHook(size_t, const void *);
43 static void FreeHook(void *, const void *);
44 static void *ReallocHook(void *, size_t, const void *);
47 static unsigned long consumption, maxConsumption;
48 // Variables to save original hooks.
49 static void *(*old_malloc_hook)(size_t, const void *);
50 static void (*old_free_hook)(void *, const void *);
51 static void *(*old_realloc_hook)(void *, size_t, const void *);
52 static AllocatedBlocks blocks;