Leaked source code of windows server 2003
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.

105 lines
2.8 KiB

  1. //
  2. // mem.h
  3. //
  4. #ifndef MEM_H
  5. #define MEM_H
  6. #include "private.h"
  7. #ifdef __cplusplus
  8. extern "C" {
  9. #endif
  10. #ifndef DEBUG
  11. void *cicMemAlloc(UINT uCount);
  12. void *cicMemAllocClear(UINT uCount);
  13. void cicMemFree(void *pv);
  14. void *cicMemReAlloc(void *pv, UINT uCount);
  15. UINT cicMemSize(void *pv);
  16. // placeholders for the debug funcs
  17. #define Dbg_MemInit(pszName, rgCounters)
  18. #define Dbg_MemUninit()
  19. #define Dbg_MemDumpStats()
  20. #define Dbg_MemSetName(pv, pszName)
  21. #define Dbg_MemGetName(pv, pch, ccBuffer)
  22. #define Dbg_MemSetThisName(pszName)
  23. #else // DEBUG
  24. typedef struct _DBG_MEM_COUNTER
  25. {
  26. const TCHAR *pszDesc;
  27. ULONG uCount;
  28. } DBG_MEM_COUNTER;
  29. typedef struct _DBG_MEMALLOC
  30. {
  31. void *pvAlloc; // the allocated memory
  32. UINT uCount; // size of allocated mem
  33. TCHAR *pszName; // debug string
  34. const TCHAR *pszFile; // file in which alloc occurred
  35. int iLine; // line num of alloc file
  36. DWORD dwThreadID; // Thread ID
  37. DWORD dwID; // unique id (by object type)
  38. struct _DBG_MEMALLOC *next;
  39. } DBG_MEMALLOC;
  40. typedef struct
  41. {
  42. UINT uTotalAlloc;
  43. UINT uTotalFree;
  44. long uTotalMemAllocCalls;
  45. long uTotalMemAllocClearCalls;
  46. long uTotalMemReAllocCalls;
  47. long uTotalMemFreeCalls;
  48. DBG_MEMALLOC *pMemAllocList;
  49. TCHAR *pszName;
  50. } DBG_MEMSTATS;
  51. BOOL Dbg_MemInit(const TCHAR *pszName, DBG_MEM_COUNTER *rgCounters);
  52. BOOL Dbg_MemUninit();
  53. void Dbg_MemDumpStats();
  54. void *Dbg_MemAlloc(UINT uCount, const TCHAR *pszFile, int iLine);
  55. void *Dbg_MemAllocClear(UINT uCount, const TCHAR *pszFile, int iLine);
  56. void Dbg_MemFree(void *pv);
  57. void *Dbg_MemReAlloc(void *pv, UINT uCount, const TCHAR *pszFile, int iLine);
  58. UINT Dbg_MemSize(void *pv);
  59. BOOL Dbg_MemSetName(void *pv, const TCHAR *pszName);
  60. BOOL Dbg_MemSetNameID(void *pv, const TCHAR *pszName, DWORD dwID);
  61. BOOL Dbg_MemSetNameIDCounter(void *pv, const TCHAR *pszName, DWORD dwID, ULONG iCounter);
  62. int Dbg_MemGetName(void *pv, TCHAR *pch, int ccBuffer);
  63. #define cicMemAlloc(uCount) Dbg_MemAlloc(uCount, TEXT(__FILE__), __LINE__)
  64. #define cicMemAllocClear(uCount) Dbg_MemAllocClear(uCount, TEXT(__FILE__), __LINE__)
  65. #define cicMemFree(pv) Dbg_MemFree(pv)
  66. #define cicMemReAlloc(pv, uCount) Dbg_MemReAlloc(pv, uCount, TEXT(__FILE__), __LINE__)
  67. #define cicMemSize(pv) Dbg_MemSize(pv)
  68. // helpers
  69. #define Dbg_MemSetThisName(pszName) Dbg_MemSetNameID(this, pszName, (DWORD)-1)
  70. #endif // DEBUG
  71. #ifdef __cplusplus
  72. } // extern "C"
  73. #endif
  74. #ifdef __cplusplus
  75. #ifdef DEBUG
  76. inline void * __cdecl operator new(size_t nSize, const TCHAR *pszFile, int iLine)
  77. {
  78. return Dbg_MemAllocClear(nSize, pszFile, iLine);
  79. }
  80. #define new new(TEXT(__FILE__), __LINE__)
  81. #endif // DEBUG
  82. #endif // __cplusplus
  83. #endif // MEM_H