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.

205 lines
6.2 KiB

  1. #ifndef _DYNAMIC_DEBUG_HEAP_HPP_
  2. #define _DYNAMIC_DEBUG_HEAP_HPP_
  3. // Ruler
  4. // 1 2 3 4 5 6 7 8
  5. //345678901234567890123456789012345678901234567890123456789012345678901234567890
  6. /********************************************************************/
  7. /* */
  8. /* The standard layout. */
  9. /* */
  10. /* The standard layout for 'hpp' files for this code is as */
  11. /* follows: */
  12. /* */
  13. /* 1. Include files. */
  14. /* 2. Constants exported from the class. */
  15. /* 3. Data structures exported from the class. */
  16. /* 4. Forward references to other data structures. */
  17. /* 5. Class specifications (including inline functions). */
  18. /* 6. Additional large inline functions. */
  19. /* */
  20. /* Any portion that is not required is simply omitted. */
  21. /* */
  22. /********************************************************************/
  23. #include "DebugHeap.hpp"
  24. #include "FastHeap.hpp"
  25. #include "PageHeap.hpp"
  26. #include "SmallHeap.hpp"
  27. /********************************************************************/
  28. /* */
  29. /* Class forward references. */
  30. /* */
  31. /* We need to refer to the following classes before they are */
  32. /* fully specified so here we list them as forward references. */
  33. /* */
  34. /********************************************************************/
  35. class LIST;
  36. struct DYNAMIC_HEAP;
  37. /********************************************************************/
  38. /* */
  39. /* A dynamic debug heap. */
  40. /* */
  41. /* A dynamic debug heap switches all allocations between a */
  42. /* standard 'FAST_HEAP', a 'DEBUG_HEAP' and a 'PAGE_HEAP' in */
  43. /* proportion to the supplied ratios. The dynamic spread means */
  44. /* that the heap is typically quite fast but occasional random */
  45. /* allocations are heavily checked by the debugging features. */
  46. /* */
  47. /********************************************************************/
  48. class ROCKALL_DLL_LINKAGE DYNAMIC_DEBUG_HEAP : public SMALL_HEAP
  49. {
  50. //
  51. // Private data.
  52. //
  53. bool Active;
  54. LIST *AllHeaps;
  55. DYNAMIC_HEAP *Array;
  56. DYNAMIC_HEAP *HeapWalk;
  57. DEBUG_HEAP DebugHeap;
  58. FAST_HEAP FastHeap;
  59. PAGE_HEAP PageHeap;
  60. int PercentDebug;
  61. int PercentPage;
  62. public:
  63. //
  64. // Public functions.
  65. //
  66. DYNAMIC_DEBUG_HEAP
  67. (
  68. int MaxFreeSpace = (2 * HalfMegabyte),
  69. bool Recycle = false,
  70. bool SingleImage = true,
  71. bool ThreadSafe = true,
  72. //
  73. // Additional debug flags.
  74. //
  75. bool FunctionTrace = false,
  76. int PercentToDebug = 20,
  77. int PercentToPage = 5,
  78. bool TrapOnUserError = true
  79. );
  80. //
  81. // Manipulate allocations.
  82. //
  83. // The first group of functions manipulate
  84. // single or small arrays of allocations.
  85. //
  86. virtual bool Delete
  87. (
  88. void *Address,
  89. int Size = NoSize
  90. );
  91. virtual bool Details
  92. (
  93. void *Address,
  94. int *Space = NULL
  95. );
  96. virtual void HeapLeaks( void );
  97. virtual bool KnownArea( void *Address );
  98. virtual bool MultipleDelete
  99. (
  100. int Actual,
  101. void *Array[],
  102. int Size = NoSize
  103. );
  104. virtual bool MultipleNew
  105. (
  106. int *Actual,
  107. void *Array[],
  108. int Requested,
  109. int Size,
  110. int *Space = NULL,
  111. bool Zero = false
  112. );
  113. virtual void *New
  114. (
  115. int Size,
  116. int *Space = NULL,
  117. bool Zero = false
  118. );
  119. virtual void *Resize
  120. (
  121. void *Address,
  122. int NewSize,
  123. int Move = -64,
  124. int *Space = NULL,
  125. bool NoDelete = false,
  126. bool Zero = false
  127. );
  128. virtual bool Verify
  129. (
  130. void *Address = NULL,
  131. int *Space = NULL
  132. );
  133. //
  134. // Manipulate the heap.
  135. //
  136. // The second group of functions act upon a heap
  137. // as a whole.
  138. //
  139. virtual void DeleteAll( bool Recycle = true );
  140. virtual void LockAll( void );
  141. virtual bool Truncate( int MaxFreeSpace = 0 );
  142. virtual void UnlockAll( void );
  143. virtual bool Walk
  144. (
  145. bool *Active,
  146. void **Address,
  147. int *Space
  148. );
  149. ~DYNAMIC_DEBUG_HEAP( void );
  150. protected:
  151. //
  152. // Protected inline functions.
  153. //
  154. // We would like to allow access to the internal
  155. // heap allocation function from classes that
  156. // inherit from the heap. The memory supplied by
  157. // this function survies all heap operations and
  158. // is cleaned up as poart of heap deletion.
  159. //
  160. virtual void *SpecialNew( int Size );
  161. private:
  162. //
  163. // Private functions.
  164. //
  165. int RandomNumber( void );
  166. //
  167. // Disabled operations.
  168. //
  169. // All copy constructors and class assignment
  170. // operations are disabled.
  171. //
  172. DYNAMIC_DEBUG_HEAP( const DYNAMIC_DEBUG_HEAP & Copy );
  173. void operator=( const DYNAMIC_DEBUG_HEAP & Copy );
  174. };
  175. #endif