Open Source Tomb Raider Engine
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

memory_test.h 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*!
  2. * \file include/memory_test.h
  3. * Memory testing Toolkit
  4. *
  5. * \author Mongoose
  6. */
  7. #ifndef _MEMORY_TEST_H_
  8. #define _MEMORY_TEST_H_
  9. #include <cstddef>
  10. #if defined(DEBUG_MEMORY) && !defined(UNIT_TEST_MEMORY)
  11. #define DEBUG_NEW new(__FILE__, __LINE__)
  12. void *operator new(size_t size, const char *file, int line);
  13. void *operator new [](size_t size, const char *file, int line);
  14. #define DEBUG_DELETE delete_check(__FILE__, __LINE__, 0);delete
  15. void operator delete(void *p);
  16. void operator delete [](void *p);
  17. #else
  18. #define DEBUG_NEW new
  19. #define DEBUG_DELETE delete
  20. #endif
  21. #define new DEBUG_NEW
  22. #define delete DEBUG_DELETE
  23. void delete_check(const char *file, int line, int print);
  24. void display_memory_usage();
  25. /*!
  26. * \brief Get total memory usage
  27. * \returns amount of total memory used
  28. */
  29. long memory_used();
  30. /*!
  31. * \brief Dumps raw Tree holding memory accounting
  32. */
  33. void dump_memory_report();
  34. #ifdef DEBUG_MEMORY
  35. #define DWORD unsigned long
  36. #define ZERO_ALLOC_SLOTS 3
  37. typedef enum { RB_BLACK = 0, RB_RED = 1 } rbtree_color_t;
  38. typedef struct rbtree_s {
  39. void *data;
  40. DWORD key;
  41. rbtree_color_t color;
  42. struct rbtree_s *left;
  43. struct rbtree_s *right;
  44. struct rbtree_s *parent;
  45. } rbtree_t;
  46. typedef struct meminfo_filename_s {
  47. char *filename;
  48. char filename_len;
  49. DWORD size;
  50. unsigned int alloc_zero;
  51. unsigned short int alloc_zero_at_line[ZERO_ALLOC_SLOTS];
  52. struct meminfo_filename_s *next;
  53. } meminfo_filename_t;
  54. #endif
  55. #endif