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.

181 lines
4.2 KiB

  1. /***************************************************************************\
  2. *
  3. * File: SimpleHelp.inl
  4. *
  5. * History:
  6. * 11/26/1999: JStall: Created
  7. *
  8. * Copyright (C) 2000 by Microsoft Corporation. All rights reserved.
  9. *
  10. \***************************************************************************/
  11. #if !defined(BASE__SimpleHeap_inl__INCLUDED)
  12. #define BASE__SimpleHeap_inl__INCLUDED
  13. #pragma once
  14. class ProcessHeap
  15. {
  16. public:
  17. static DUserHeap * GetHeap()
  18. {
  19. return pProcessHeap;
  20. }
  21. };
  22. class ContextHeap
  23. {
  24. public:
  25. static DUserHeap * GetHeap()
  26. {
  27. return pContextHeap;
  28. }
  29. };
  30. #if DBG
  31. //------------------------------------------------------------------------------
  32. template <class type>
  33. inline type *
  34. DoProcessNewDbg(const char * pszFileName, int idxLineNum)
  35. {
  36. void * pvMem = pProcessHeap->Alloc(sizeof(type), true, pszFileName, idxLineNum);
  37. if (pvMem != NULL) {
  38. placement_new(pvMem, type);
  39. }
  40. return reinterpret_cast<type *> (pvMem);
  41. }
  42. //------------------------------------------------------------------------------
  43. template <class type>
  44. inline type *
  45. DoClientNewDbg(const char * pszFileName, int idxLineNum)
  46. {
  47. void * pvMem = pContextHeap->Alloc(sizeof(type), true, pszFileName, idxLineNum);
  48. if (pvMem != NULL) {
  49. placement_new(pvMem, type);
  50. }
  51. return reinterpret_cast<type *> (pvMem);
  52. }
  53. //------------------------------------------------------------------------------
  54. template <class type>
  55. inline type *
  56. DoContextNewDbg(DUserHeap * pHeap, const char * pszFileName, int idxLineNum)
  57. {
  58. void * pvMem = pHeap->Alloc(sizeof(type), true, pszFileName, idxLineNum);
  59. if (pvMem != NULL) {
  60. placement_new(pvMem, type);
  61. }
  62. return reinterpret_cast<type *> (pvMem);
  63. }
  64. #else // DBG
  65. //------------------------------------------------------------------------------
  66. template <class type>
  67. inline type *
  68. DoProcessNew()
  69. {
  70. void * pvMem = pProcessHeap->Alloc(sizeof(type), true);
  71. if (pvMem != NULL) {
  72. placement_new(pvMem, type);
  73. }
  74. return reinterpret_cast<type *> (pvMem);
  75. }
  76. //------------------------------------------------------------------------------
  77. template <class type>
  78. inline type *
  79. DoClientNew()
  80. {
  81. void * pvMem = pContextHeap->Alloc(sizeof(type), true);
  82. if (pvMem != NULL) {
  83. placement_new(pvMem, type);
  84. }
  85. return reinterpret_cast<type *> (pvMem);
  86. }
  87. //------------------------------------------------------------------------------
  88. template <class type>
  89. inline type *
  90. DoContextNew(DUserHeap * pHeap)
  91. {
  92. void * pvMem = pHeap->Alloc(sizeof(type), true);
  93. if (pvMem != NULL) {
  94. placement_new(pvMem, type);
  95. }
  96. return reinterpret_cast<type *> (pvMem);
  97. }
  98. #endif // DBG
  99. //------------------------------------------------------------------------------
  100. template <class type>
  101. inline void
  102. DoProcessDelete(type * pMem)
  103. {
  104. if (pMem != NULL) {
  105. #if ENABLE_DUMPDELETE
  106. Trace("Start ProcessFree(0x%p), size=%d\n", pMem, sizeof(type));
  107. #endif // ENABLE_DUMPDELETE
  108. placement_delete(pMem, type);
  109. #if ENABLE_DUMPDELETE
  110. Trace("Dump ProcessFree(0x%p), size=%d\n", pMem, sizeof(type));
  111. DumpData(pMem, sizeof(type));
  112. #endif // ENABLE_DUMPDELETE
  113. pProcessHeap->Free(pMem);
  114. }
  115. }
  116. //------------------------------------------------------------------------------
  117. template <class type>
  118. inline void
  119. DoClientDelete(type * pMem)
  120. {
  121. if (pMem != NULL) {
  122. placement_delete(pMem, type);
  123. pContextHeap->Free(pMem);
  124. }
  125. }
  126. //------------------------------------------------------------------------------
  127. template <class type>
  128. inline void
  129. DoContextDelete(DUserHeap * pHeap, type * pMem)
  130. {
  131. if (pMem != NULL) {
  132. placement_delete(pMem, type);
  133. pHeap->Free(pMem);
  134. }
  135. }
  136. #if !DBG
  137. //------------------------------------------------------------------------------
  138. inline void
  139. DumpData(
  140. IN void * pMem,
  141. IN int nLength)
  142. {
  143. UNREFERENCED_PARAMETER(pMem);
  144. UNREFERENCED_PARAMETER(nLength);
  145. }
  146. #endif // DBG
  147. #endif // BASE__SimpleHeap_inl__INCLUDED