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.

180 lines
4.9 KiB

  1. #ifndef _ZONE_HEAP_HPP_
  2. #define _ZONE_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 "Rockall.hpp"
  24. #pragma warning( disable : 4100 )
  25. /********************************************************************/
  26. /* */
  27. /* A zone heap. */
  28. /* */
  29. /* A zone heap simply allocates a large amount of space and */
  30. /* allocates space by advancing a pointer down an array. */
  31. /* There is no way to free space except by deleting it all. */
  32. /* */
  33. /********************************************************************/
  34. class ROCKALL_DLL_LINKAGE ZONE_HEAP : public ROCKALL
  35. {
  36. //
  37. // Private type definitions.
  38. //
  39. typedef struct
  40. {
  41. char *Start;
  42. char *End;
  43. }
  44. ZONE;
  45. //
  46. // Private data.
  47. //
  48. int MaxSize;
  49. bool ThreadLocks;
  50. ZONE Zone;
  51. public:
  52. //
  53. // Public functions.
  54. //
  55. ZONE_HEAP
  56. (
  57. int MaxFreeSpace = 4194304,
  58. bool Recycle = true,
  59. bool SingleImage = false,
  60. bool ThreadSafe = true
  61. );
  62. //
  63. // Manipulate allocations.
  64. //
  65. // The first group of functions manipulate
  66. // single or small arrays of allocations.
  67. //
  68. virtual bool Delete
  69. (
  70. void *Address,
  71. int Size = NoSize
  72. )
  73. { return false; }
  74. virtual bool Details
  75. (
  76. void *Address,
  77. int *Space = NULL
  78. )
  79. { return false; }
  80. virtual bool MultipleDelete
  81. (
  82. int Actual,
  83. void *Array[],
  84. int Size = NoSize
  85. )
  86. { return false; }
  87. virtual bool MultipleNew
  88. (
  89. int *Actual,
  90. void *Array[],
  91. int Requested,
  92. int Size,
  93. int *Space = NULL,
  94. bool Zero = false
  95. );
  96. virtual void *New
  97. (
  98. int Size,
  99. int *Space = NULL,
  100. bool Zero = false
  101. );
  102. virtual void *Resize
  103. (
  104. void *Address,
  105. int NewSize,
  106. int Move = -64,
  107. int *Space = NULL,
  108. bool NoDelete = false,
  109. bool Zero = false
  110. )
  111. { return NULL; }
  112. virtual bool Verify
  113. (
  114. void *Address = NULL,
  115. int *Space = NULL
  116. )
  117. { return false; }
  118. //
  119. // Manipulate the heap.
  120. //
  121. // The second group of functions act upon a heap
  122. // as a whole.
  123. //
  124. virtual void DeleteAll( bool Recycle = true );
  125. virtual bool Walk
  126. (
  127. bool *Active,
  128. void **Address,
  129. int *Space
  130. )
  131. { return false; }
  132. ~ZONE_HEAP( void );
  133. private:
  134. //
  135. // Private functions.
  136. //
  137. bool UpdateZone( ZONE *Original,ZONE *Update );
  138. //
  139. // Private inline functions.
  140. //
  141. void WriteZone( ZONE *Update )
  142. {
  143. auto ZONE Original = Zone;
  144. while ( ! UpdateZone( & Original,Update ) )
  145. { Original = Zone; }
  146. }
  147. //
  148. // Disabled operations.
  149. //
  150. // All copy constructors and class assignment
  151. // operations are disabled.
  152. //
  153. ZONE_HEAP( const ZONE_HEAP & Copy );
  154. void operator=( const ZONE_HEAP & Copy );
  155. };
  156. #pragma warning( default : 4100 )
  157. #endif