Heap.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. #if !defined(HEAP_H)
  18. #define HEAP_H
  19. #if defined(HIGH_PERFORMANCE)
  20. #define NO_HEAP_TRACKING 1
  21. #endif
  22. #include <stdio.h>
  23. #include <stdlib.h>
  24. #if !defined(NO_HEAP_TRACKING)
  25. /**
  26. * redefines malloc to use "mymalloc" so that heap allocation can be tracked
  27. * @param x the size of the item to be allocated
  28. * @return the pointer to the item allocated, or NULL
  29. */
  30. #define malloc(x) mymalloc(__FILE__, __LINE__, x)
  31. /**
  32. * redefines realloc to use "myrealloc" so that heap allocation can be tracked
  33. * @param a the heap item to be reallocated
  34. * @param b the new size of the item
  35. * @return the new pointer to the heap item
  36. */
  37. #define realloc(a, b) myrealloc(__FILE__, __LINE__, a, b)
  38. /**
  39. * redefines free to use "myfree" so that heap allocation can be tracked
  40. * @param x the size of the item to be freed
  41. */
  42. #define free(x) myfree(__FILE__, __LINE__, x)
  43. #endif
  44. /**
  45. * Information about the state of the heap.
  46. */
  47. typedef struct
  48. {
  49. size_t current_size; /**< current size of the heap in bytes */
  50. size_t max_size; /**< max size the heap has reached in bytes */
  51. } heap_info;
  52. void* mymalloc(char*, int, size_t size);
  53. void* myrealloc(char*, int, void* p, size_t size);
  54. void myfree(char*, int, void* p);
  55. void Heap_scan(FILE* file);
  56. int Heap_initialize(void);
  57. void Heap_terminate(void);
  58. heap_info* Heap_get_info(void);
  59. int HeapDump(FILE* file);
  60. int HeapDumpString(FILE* file, char* str);
  61. void* Heap_findItem(void* p);
  62. void Heap_unlink(char* file, int line, void* p);
  63. #endif