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.

73 lines
3.3 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995
  5. //
  6. // File: mem.h
  7. //
  8. // Contents: Memory utility functions (has leak tracking in debug)
  9. //
  10. //----------------------------------------------------------------------------
  11. EXTERN_C void * _MemAlloc(ULONG cb);
  12. EXTERN_C void * _MemAllocClear(ULONG cb);
  13. EXTERN_C HRESULT _MemRealloc(void ** ppv, ULONG cb);
  14. EXTERN_C ULONG _MemGetSize(void * pv);
  15. EXTERN_C void _MemFree(void * pv);
  16. HRESULT _MemAllocString(LPCTSTR pchSrc, LPTSTR * ppchDst);
  17. HRESULT _MemAllocString(ULONG cch, LPCTSTR pchSrc, LPTSTR * ppchDst);
  18. HRESULT _MemReplaceString(LPCTSTR pchSrc, LPTSTR * ppchDest);
  19. void __cdecl _MemSetName(void * pv, char * szFmt, ...);
  20. #define _MemFreeString(pch) _MemFree(pch)
  21. #if defined(MEMGUARD)
  22. #define MemAlloc(cb) _MgMemAlloc(cb)
  23. #define MemAllocClear(cb) _MgMemAllocClear(cb)
  24. #define MemRealloc(ppv, cb) _MgMemRealloc(ppv, cb)
  25. #define MemGetSize(pv) _MgMemGetSize(pv)
  26. #define MemFree(pv) _MgMemFree(pv)
  27. #define MemAllocString(pch, ppch) _MgMemAllocString(pch, ppch)
  28. #define MemAllocStringBuffer(cch, pch, ppch) _MgMemAllocString(cch, pch, ppch)
  29. #define MemReplaceString(pch, ppch) _MgMemReplaceString(pch, ppch)
  30. #define MemFreeString(pch) _MgMemFreeString(pch)
  31. #else
  32. #define MemAlloc(cb) _MemAlloc(cb)
  33. #define MemAllocClear(cb) _MemAllocClear(cb)
  34. #define MemRealloc(ppv, cb) _MemRealloc(ppv, cb)
  35. #define MemGetSize(pv) _MemGetSize(pv)
  36. #define MemFree(pv) _MemFree(pv)
  37. #define MemAllocString(pch, ppch) _MemAllocString(pch, ppch)
  38. #define MemAllocStringBuffer(cch, pch, ppch) _MemAllocString(cch, pch, ppch)
  39. #define MemReplaceString(pch, ppch) _MemReplaceString(pch, ppch)
  40. #define MemFreeString(pch) _MemFreeString(pch)
  41. #endif
  42. #if DBG == 1
  43. #define MemSetName DbgExMemSetName
  44. #else
  45. #define MemSetName 0&&
  46. #endif
  47. inline void * __cdecl operator new(size_t cb) { return MemAlloc(cb); }
  48. inline void * __cdecl operator new[](size_t cb) { return MemAlloc(cb); }
  49. inline void * __cdecl operator new(size_t cb, int mt) { return MemAlloc(cb); }
  50. inline void * __cdecl operator new[](size_t cb, int mt) { return MemAlloc(cb); }
  51. inline void * __cdecl operator new(size_t cb, void * pv){ return pv; }
  52. inline void __cdecl operator delete(void *pv) { MemFree(pv); }
  53. inline void __cdecl operator delete[](void *pv) { MemFree(pv); }
  54. #define DECLARE_MEMALLOC_NEW_DELETE() \
  55. inline void * __cdecl operator new(size_t cb) { return(MemAlloc(cb)); } \
  56. inline void * __cdecl operator new[](size_t cb) { return(MemAlloc(cb)); } \
  57. inline void __cdecl operator delete(void * pv) { MemFree(pv); }
  58. #define DECLARE_MEMCLEAR_NEW_DELETE() \
  59. inline void * __cdecl operator new(size_t cb) { return(MemAllocClear(cb)); } \
  60. inline void * __cdecl operator new[](size_t cb) { return(MemAllocClear(cb)); } \
  61. inline void __cdecl operator delete(void * pv) { MemFree(pv); }