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.

78 lines
2.5 KiB

  1. /*** mem.h - Definitions for Memory Manager
  2. *
  3. * Microsoft Confidential
  4. * Copyright (C) Microsoft Corporation 1993-1994
  5. * All Rights Reserved.
  6. *
  7. * The Memory Manager is a very thin layer on top of the native memory
  8. * heap functions, allowing strong assertion checking and pointer
  9. * validation in debug builds.
  10. *
  11. * Author:
  12. * Benjamin W. Slivka
  13. *
  14. * History:
  15. * 10-Aug-1993 bens Initial version
  16. * 11-Aug-1993 bens Lift code from STOCK.EXE win app
  17. * 12-Aug-1993 bens Improved comments
  18. * 18-Mar-1994 bens strdup() now called _strdup(); renamed
  19. * 18-May-1994 bens Allow turning off MemCheckHeap() in debug build
  20. * (it can really, really slow things down!)
  21. *
  22. * Functions:
  23. * MemAlloc - Allocate memory block
  24. * MemFree - Free memory block
  25. * MemStrDup - Duplicate string to new memory block
  26. *
  27. * Functions available in ASSERT build:
  28. * MemAssert - Assert that pointer was allocated by MemAlloc
  29. * MemCheckHeap - Check entire memory heap
  30. * MemListHeap - List all heap entries (to stdout)
  31. * MemGetSize - Return allocated size of memory block
  32. * MemSetCheckHeap - Control whether MemCheckHeap is done on every
  33. * every MemAlloc and MemFree!
  34. */
  35. #ifndef INCLUDED_MEMORY
  36. #define INCLUDED_MEMORY 1
  37. #ifdef ASSERT
  38. #define MemAlloc(cb) MMAlloc(cb,__FILE__,__LINE__)
  39. #define MemFree(pv) MMFree(pv,__FILE__,__LINE__)
  40. #define MemStrDup(pv) MMStrDup(pv,__FILE__,__LINE__)
  41. #define MemAssert(pv) MMAssert(pv,__FILE__,__LINE__)
  42. #define MemCheckHeap() MMCheckHeap(__FILE__,__LINE__)
  43. #define MemListHeap() MMListHeap(__FILE__,__LINE__)
  44. int MemGetSize(void *pv);
  45. void *MMAlloc(unsigned cb, char *pszFile, int iLine);
  46. void MMFree(void *pv, char *pszFile, int iLine);
  47. void MMAssert(void *pv, char *pszFile, int iLine);
  48. void MMCheckHeap(char *pszFile, int iLine);
  49. void MMListHeap(char *pszFile, int iLine);
  50. char *MMStrDup(char *pv, char *pszFile, int iLine);
  51. void MemSetCheckHeap(BOOL f);
  52. #else // !ASSERT
  53. #include <malloc.h> // Get malloc()/free()
  54. #include <string.h> // Get _strdup()
  55. //** No Asserts
  56. #define MemAlloc(cb) malloc(cb)
  57. #define MemFree(pv) free(pv)
  58. #define MemStrDup(pv) _strdup(pv)
  59. #define MemAssert(pv)
  60. #define MemCheckHeap()
  61. #define MemListHeap()
  62. #define MemGetSize(pv)
  63. #define MemSetCheckHeap(f)
  64. #endif // !ASSERT
  65. #endif // !INCLUDED_MEMORY