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.

73 lines
1.8 KiB

  1. /*****************************************************************************
  2. *
  3. * mem.h
  4. *
  5. *****************************************************************************/
  6. /*****************************************************************************
  7. *
  8. * Arenas
  9. *
  10. * Memory is allocated in chunks called arenas. Arenas contain extra
  11. * bookkeeping in DEBUG to help catch common memory problems like
  12. * overruns and memory leaks. (It doesn't catch dangling pointers,
  13. * though.)
  14. *
  15. *****************************************************************************/
  16. typedef unsigned TM; /* Artificial time */
  17. typedef struct ARENA AR, *PAR;
  18. struct ARENA {
  19. #ifdef DEBUG
  20. PAR parNext; /* Next arena */
  21. PAR parPrev; /* Previous arena */
  22. CB cb; /* Size of rgb */
  23. TM tm; /* Timestamp used to track memory leaks */
  24. #endif
  25. BYTE rgb[4]; /* The actual data */
  26. };
  27. typedef CONST AR *PCAR;
  28. #define parPv(pv) pvSubPvCb(pv, offsetof(AR, rgb))
  29. #ifdef DEBUG
  30. extern TM g_tmNow;
  31. extern AR g_arHead;
  32. #define parHead (&g_arHead)
  33. #endif
  34. #ifdef DEBUG
  35. void STDCALL AssertPar(PCAR par);
  36. #else
  37. #define AssertPar(par)
  38. #endif
  39. void STDCALL FreePv(PVOID pv);
  40. PVOID STDCALL pvAllocCb(CB cb);
  41. PVOID STDCALL pvReallocPvCb(PVOID pv, CB cb);
  42. INLINE PTCH STDCALL
  43. ptchAllocCtch(CTCH ctch)
  44. {
  45. return pvAllocCb(cbCtch(ctch));
  46. }
  47. INLINE PTCH STDCALL
  48. ptchReallocPtchCtch(PTCH ptch, CTCH ctch)
  49. {
  50. return pvReallocPvCb(ptch, cbCtch(ctch));
  51. }
  52. /*****************************************************************************
  53. *
  54. * Garbage collection
  55. *
  56. *****************************************************************************/
  57. #ifdef DEBUG
  58. void STDCALL Gc(void);
  59. #else
  60. #define Gc()
  61. #endif