1 /******************************************************************************* 2 * Copyright (c) 2009, 2013 IBM Corp. 3 * 4 * All rights reserved. This program and the accompanying materials 5 * are made available under the terms of the Eclipse Public License v1.0 6 * and Eclipse Distribution License v1.0 which accompany this distribution. 7 * 8 * The Eclipse Public License is available at 9 * http://www.eclipse.org/legal/epl-v10.html 10 * and the Eclipse Distribution License is available at 11 * http://www.eclipse.org/org/documents/edl-v10.php. 12 * 13 * Contributors: 14 * Ian Craggs - initial API and implementation and/or initial documentation 15 * Ian Craggs - use tree data structure instead of list 16 *******************************************************************************/ 17 18 19 #if !defined(HEAP_H) 20 #define HEAP_H 21 22 #if defined(HIGH_PERFORMANCE) 23 #define NO_HEAP_TRACKING 1 24 #endif 25 26 #include <stdio.h> 27 #include <stdlib.h> 28 29 #if !defined(NO_HEAP_TRACKING) 30 /** 31 * redefines malloc to use "mymalloc" so that heap allocation can be tracked 32 * @param x the size of the item to be allocated 33 * @return the pointer to the item allocated, or NULL 34 */ 35 #define malloc(x) mymalloc(__FILE__, __LINE__, x) 36 37 /** 38 * redefines realloc to use "myrealloc" so that heap allocation can be tracked 39 * @param a the heap item to be reallocated 40 * @param b the new size of the item 41 * @return the new pointer to the heap item 42 */ 43 #define realloc(a, b) myrealloc(__FILE__, __LINE__, a, b) 44 45 /** 46 * redefines free to use "myfree" so that heap allocation can be tracked 47 * @param x the size of the item to be freed 48 */ 49 #define free(x) myfree(__FILE__, __LINE__, x) 50 51 #endif 52 53 /** 54 * Information about the state of the heap. 55 */ 56 typedef struct 57 { 58 size_t current_size; /**< current size of the heap in bytes */ 59 size_t max_size; /**< max size the heap has reached in bytes */ 60 } heap_info; 61 62 #if defined(__cplusplus) 63 extern "C" { 64 #endif 65 66 void* mymalloc(char*, int, size_t size); 67 void* myrealloc(char*, int, void* p, size_t size); 68 void myfree(char*, int, void* p); 69 70 void Heap_scan(FILE* file); 71 int Heap_initialize(void); 72 void Heap_terminate(void); 73 heap_info* Heap_get_info(void); 74 int HeapDump(FILE* file); 75 int HeapDumpString(FILE* file, char* str); 76 void* Heap_findItem(void* p); 77 void Heap_unlink(char* file, int line, void* p); 78 #ifdef __cplusplus 79 } 80 #endif 81 82 #endif 83