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.

101 lines
2.4 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. basemem.h
  5. Abstract:
  6. Implements macros and declares functions for basic allocation functions.
  7. Consolidated into this file from debug.h and allutils.h
  8. Author:
  9. Marc R. Whitten (marcw) 09-Sep-1999
  10. Revision History:
  11. --*/
  12. #pragma once
  13. #ifdef _cplusplus
  14. extern "C" {
  15. #endif
  16. #define INVALID_PTR ((PVOID)-1)
  17. //
  18. // Fail-proof memory allocators
  19. //
  20. PVOID SafeHeapAlloc (HANDLE g_hHeap, DWORD Flags, SIZE_T Size);
  21. PVOID SafeHeapReAlloc (HANDLE g_hHeap, DWORD Flags, PVOID OldBlock, SIZE_T Size);
  22. //
  23. // Reusable memory alloc, kind of like a GROWBUFFER but more simple
  24. //
  25. PVOID ReuseAlloc (HANDLE Heap, PVOID OldPtr, DWORD SizeNeeded);
  26. VOID ReuseFree (HANDLE Heap,PVOID Ptr);
  27. #ifdef DEBUG
  28. #define MemAlloc(heap,flags,size) DebugHeapAlloc(__FILE__,__LINE__,heap,flags,size)
  29. #define MemReAlloc(heap,flags,ptr,size) DebugHeapReAlloc(__FILE__,__LINE__,heap,flags,ptr,size)
  30. #define MemFree(heap,flags,ptr) DebugHeapFree(__FILE__,__LINE__,heap,flags,ptr)
  31. #define MemCheck(x) DebugHeapCheck(__FILE__,__LINE__,heap)
  32. #define FreeAlloc(ptr) DebugHeapFree(__FILE__,__LINE__,g_hHeap,0,ptr)
  33. #define MemAllocUninit(size) DebugHeapAlloc(__FILE__,__LINE__,g_hHeap,0,size)
  34. #define MemAllocZeroed(size) DebugHeapAlloc(__FILE__,__LINE__,g_hHeap,HEAP_ZERO_MEMORY,size)
  35. LPVOID DebugHeapAlloc (LPCSTR File, DWORD Line, HANDLE hHeap, DWORD dwFlags, SIZE_T dwSize);
  36. LPVOID DebugHeapReAlloc (LPCSTR File, DWORD Line, HANDLE hHeap, DWORD dwFlags, LPCVOID pMem, SIZE_T dwSize);
  37. BOOL DebugHeapFree (LPCSTR File, DWORD Line, HANDLE hHeap, DWORD dwFlags, LPCVOID pMem);
  38. void DebugHeapCheck (LPCSTR File, DWORD Line, HANDLE hHeap);
  39. VOID DumpHeapStats (VOID);
  40. VOID DumpHeapLeaks (VOID);
  41. SIZE_T
  42. DebugHeapValidatePtr (
  43. HANDLE hHeap,
  44. PCVOID CallerPtr,
  45. PCSTR File,
  46. DWORD Line
  47. );
  48. #define MemCheckPtr(heap,ptr) (DebugHeapValidatePtr(heap,ptr,__FILE__,__LINE__) != INVALID_PTR)
  49. #else
  50. #define MemAlloc SafeHeapAlloc
  51. #define MemReAlloc SafeHeapReAlloc
  52. #define MemFree(x,y,z) HeapFree(x,y,(PVOID)(z))
  53. #define MemCheck(x)
  54. #define FreeAlloc(ptr) HeapFree(g_hHeap,0,(PVOID)(ptr))
  55. #define MemAllocUninit(size) SafeHeapAlloc(g_hHeap,0,size)
  56. #define MemAllocZeroed(size) SafeHeapAlloc(g_hHeap,HEAP_ZERO_MEMORY,size)
  57. #define DebugHeapCheck(x,y,z)
  58. #define DumpHeapStats()
  59. #define DumpHeapLeaks()
  60. #define MemCheckPtr(heap,ptr) (1)
  61. #endif
  62. #ifdef _cplusplus
  63. }
  64. #endif