Open Source Tomb Raider Engine
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

memory_test.h 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. typedef enum {
  24. MEMORY_USED_BY_PROGRAM = 1,
  25. MEMORY_USED_BY_OVERHEAD = 2,
  26. MEMORY_USED_TOTAL = 3,
  27. MAX_MEMORY_USED_BY_PROGRAM = 4,
  28. MAX_MEMORY_USED_BY_OVERHEAD = 5
  29. } memory_query_t;
  30. void delete_check(const char *file, int line, int print);
  31. void display_memory_usage();
  32. /*!
  33. * \brief Get total memory usage
  34. * \param query what to return
  35. * \returns amount of requested memory used
  36. */
  37. long memory_used(memory_query_t query);
  38. /*!
  39. * \brief Dumps raw Tree holding memory accounting
  40. */
  41. void dump_memory_report();
  42. #ifdef DEBUG_MEMORY
  43. #define DWORD unsigned long
  44. #define ZERO_ALLOC_SLOTS 3
  45. typedef enum { RB_BLACK = 0, RB_RED = 1 } rbtree_color_t;
  46. typedef struct rbtree_s {
  47. void *data;
  48. DWORD key;
  49. rbtree_color_t color;
  50. struct rbtree_s *left;
  51. struct rbtree_s *right;
  52. struct rbtree_s *parent;
  53. } rbtree_t;
  54. typedef struct meminfo_filename_s {
  55. char *filename;
  56. char filename_len;
  57. DWORD size;
  58. unsigned int alloc_zero;
  59. unsigned int alloc_zero_at_line[ZERO_ALLOC_SLOTS];
  60. struct meminfo_filename_s *next;
  61. } meminfo_filename_t;
  62. #endif
  63. #endif