memory.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #ifndef MEMORY_H
  2. #define MEMORY_H
  3. #include "ik/config.h"
  4. #ifdef IK_MEMORY_DEBUGGING
  5. # define MALLOC malloc_wrapper
  6. # define FREE free_wrapper
  7. #else
  8. # include <stdlib.h>
  9. # define MALLOC malloc
  10. # define FREE free
  11. #endif
  12. C_HEADER_BEGIN
  13. /*!
  14. * @brief Initialises the memory system.
  15. *
  16. * In release mode this does nothing. In debug mode it will initialise
  17. * memory reports and backtraces, if enabled.
  18. */
  19. IK_PUBLIC_API void
  20. ik_memory_init(void);
  21. /*!
  22. * @brief De-initialises the memory system.
  23. *
  24. * In release mode this does nothing. In debug mode this will output the memory
  25. * report and print backtraces, if enabled.
  26. * @return Returns the number of memory leaks.
  27. */
  28. IK_PUBLIC_API uintptr_t
  29. ik_memory_deinit(void);
  30. #ifdef IK_MEMORY_DEBUGGING
  31. /*!
  32. * @brief Does the same thing as a normal call to malloc(), but does some
  33. * additional work to monitor and track down memory leaks.
  34. */
  35. IK_PUBLIC_API void*
  36. malloc_wrapper(intptr_t size);
  37. /*!
  38. * @brief Does the same thing as a normal call to fee(), but does some
  39. * additional work to monitor and track down memory leaks.
  40. */
  41. IK_PUBLIC_API void
  42. free_wrapper(void* ptr);
  43. #endif /* IK_MEMORY_DEBUGGING */
  44. IK_PUBLIC_API void
  45. mutated_string_and_hex_dump(void* data, intptr_t size_in_bytes);
  46. C_HEADER_END
  47. #endif /* MEMORY_H */