Source code of Windows XP (NT5)
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.

114 lines
3.2 KiB

  1. //
  2. // MEMTRACK.H
  3. // Standard NetMeeting memory leak tracking.
  4. //
  5. // In retail:
  6. // new/MemAlloc become LocalAlloc()
  7. // MemReAlloc becomes LocalReAlloc()
  8. // delete/MemFree become LocalFree()
  9. //
  10. // In debug:
  11. // allocations are tracked, with module/file/line number
  12. // leaked blocks are spewed when the module unloads
  13. //
  14. //
  15. // USAGE:
  16. // (1) Include this header and link to NMUTIL
  17. // (2) If your component requires zero-initialized memory, define
  18. // _MEM_ZEROINIT (for both debug and retail) in your SOURCES file
  19. // (3) In your DllMain, on DLL_PROCESS_ATTACH call DBG_INIT_MEMORY_TRACKING,
  20. // and on DLL_PROCESS_DETACH call DBG_CHECK_MEMORY_TRACKING
  21. // (4) In DEBUG, you can make a call to DbgMemTrackDumpCurrent() to dump
  22. // the currently allocated memory list from code.
  23. //
  24. #ifndef _MEMTRACK_H
  25. #define _MEMTRACK_H
  26. #ifdef __cplusplus
  27. extern "C" {
  28. #endif
  29. //
  30. // MEMORY ALLOCATIONS/TRACKING
  31. //
  32. //
  33. // GUI message boxes kill us when we hit an assert or error, because they
  34. // have a message pump that causes messages to get dispatched, making it
  35. // very difficult for us to debug problems when they occur. Therefore
  36. // we redefine ERROR_OUT and ASSERT
  37. //
  38. #ifdef DEBUG
  39. #undef assert
  40. #define assert(x) ASSERT(x)
  41. void WINAPI DbgMemTrackDumpCurrent(void);
  42. void WINAPI DbgMemTrackFinalCheck(void);
  43. LPVOID WINAPI DbgMemAlloc(UINT cbSize, LPVOID caller, LPSTR pszFileName, UINT nLineNumber);
  44. void WINAPI DbgMemFree(LPVOID ptr);
  45. LPVOID WINAPI DbgMemReAlloc(LPVOID ptr, UINT cbSize, UINT uFlags, LPSTR pszFileName, UINT nLineNumber);
  46. #define DBG_CHECK_MEMORY_TRACKING(hInst) DbgMemTrackFinalCheck()
  47. #define MemAlloc(cbSize) DbgMemAlloc(cbSize, NULL, __FILE__, __LINE__)
  48. #ifdef _MEM_ZEROINIT
  49. #define MemReAlloc(pObj, cbSize) DbgMemReAlloc((pObj), (cbSize), LMEM_MOVEABLE | LMEM_ZEROINIT, __FILE__, __LINE__)
  50. #else
  51. #define MemReAlloc(pObj, cbSize) DbgMemReAlloc((pObj), (cbSize), LMEM_MOVEABLE, __FILE__, __LINE__)
  52. #endif //_MEM_ZEROINIT
  53. #define MemFree(pObj) DbgMemFree(pObj)
  54. void WINAPI DbgSaveFileLine(LPSTR pszFileName, UINT nLineNumber);
  55. #define DBG_SAVE_FILE_LINE DbgSaveFileLine(__FILE__, __LINE__);
  56. // RETAIL
  57. #else
  58. #define DBG_CHECK_MEMORY_TRACKING(hInst)
  59. #ifdef _MEM_ZEROINIT
  60. #define MemAlloc(cbSize) LocalAlloc(LPTR, (cbSize))
  61. #define MemReAlloc(pObj, cbSize) LocalReAlloc((pObj), (cbSize), LMEM_MOVEABLE | LMEM_ZEROINIT)
  62. #else
  63. #define MemAlloc(cbSize) LocalAlloc(LMEM_FIXED, (cbSize))
  64. #define MemReAlloc(pObj, cbSize) LocalReAlloc((pObj), (cbSize), LMEM_MOVEABLE)
  65. #endif // _MEM_ZEROINIT
  66. #define MemFree(pObj) LocalFree(pObj)
  67. #define DBG_SAVE_FILE_LINE
  68. #endif // DEBUG
  69. void WINAPI DbgInitMemTrack(HINSTANCE hDllInst, BOOL fZeroOut);
  70. #ifdef _MEM_ZEROINIT
  71. #define DBG_INIT_MEMORY_TRACKING(hInst) DbgInitMemTrack(hInst, TRUE)
  72. #else
  73. #define DBG_INIT_MEMORY_TRACKING(hInst) DbgInitMemTrack(hInst, FALSE)
  74. #endif //_MEM_ZEROINIT
  75. #define MEMALLOC(cb) MemAlloc(cb)
  76. #define MEMREALLOC(p, cb) MemReAlloc(p, cb)
  77. #define MEMFREE(p) MemFree(p)
  78. #ifdef __cplusplus
  79. }
  80. #endif
  81. #endif // #ifndef _MEMTRACK_H