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.

289 lines
9.0 KiB

  1. #ifndef _ROCKALL_HPP_
  2. #define _ROCKALL_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 <stddef.h>
  24. /********************************************************************/
  25. /* */
  26. /* Memory allocation constants. */
  27. /* */
  28. /* The memory allocation constants are denote special situations */
  29. /* where optimizations are possible or failures have cccured. */
  30. /* */
  31. /********************************************************************/
  32. const int AllocationFailure = 0;
  33. const int GuardValue = 0xDeadBeef;
  34. const int NoSize = -1;
  35. /********************************************************************/
  36. /* */
  37. /* Class forward references. */
  38. /* */
  39. /* We need to refer to the following classes before they are */
  40. /* fully specified so here we list them as forward references. */
  41. /* */
  42. /********************************************************************/
  43. class CACHE;
  44. class FIND;
  45. class HEAP;
  46. class NEW_PAGE;
  47. /********************************************************************/
  48. /* */
  49. /* Linkage to the DLL. */
  50. /* */
  51. /* We need to compile the class specification slightly */
  52. /* differently if we are creating the heap DLL. */
  53. /* */
  54. /********************************************************************/
  55. #ifdef COMPILING_ROCKALL_DLL
  56. #define ROCKALL_DLL_LINKAGE __declspec(dllexport)
  57. #else
  58. #ifdef COMPILING_ROCKALL_LIBRARY
  59. #define ROCKALL_DLL_LINKAGE
  60. #else
  61. #define ROCKALL_DLL_LINKAGE __declspec(dllimport)
  62. #endif
  63. #endif
  64. /********************************************************************/
  65. /* */
  66. /* The memory allocation interface. */
  67. /* */
  68. /* The memory allocator can be configured in a wide variety */
  69. /* of ways to closely match the needs of specific programs. */
  70. /* The interface outlined here can be overloaded to support */
  71. /* whatever customization is necessary. */
  72. /* */
  73. /********************************************************************/
  74. class ROCKALL_DLL_LINKAGE ROCKALL
  75. {
  76. public:
  77. //
  78. // Public types.
  79. //
  80. // A heap is constructed of a collection of
  81. // fixed sized buckets each with an associated
  82. // cache. The details of these buckets are
  83. // supplied to the heap using the following
  84. // structure.
  85. //
  86. typedef struct
  87. {
  88. int AllocationSize;
  89. int CacheSize;
  90. int ChunkSize;
  91. int PageSize;
  92. }
  93. CACHE_DETAILS;
  94. //
  95. // Public data.
  96. //
  97. // The internals linkages in a heap are built
  98. // dynamically during the execution of a heaps
  99. // constructor. The member that follow relate
  100. // to key internal classes.
  101. //
  102. CACHE **Array;
  103. CACHE *Caches;
  104. FIND *Find;
  105. HEAP *Heap;
  106. NEW_PAGE *NewPage;
  107. //
  108. // A heap constructor is required to preserve
  109. // a small amount of information for the heap
  110. // destructor.
  111. //
  112. bool GlobalDelete;
  113. int GuardWord;
  114. int NumberOfCaches;
  115. int TotalSize;
  116. //
  117. // Public functions.
  118. //
  119. // A heaps public interface consists of a number
  120. // of groups of related APIs.
  121. //
  122. ROCKALL( void );
  123. ROCKALL
  124. (
  125. CACHE_DETAILS *Caches1,
  126. CACHE_DETAILS *Caches2,
  127. int FindCacheSize,
  128. int FindCacheThreshold,
  129. int FindSize,
  130. int MaxFreeSpace,
  131. int *NewPageSizes,
  132. bool Recycle,
  133. bool SingleImage,
  134. int Stride1,
  135. int Stride2,
  136. bool ThreadSafe
  137. );
  138. //
  139. // Manipulate allocations.
  140. //
  141. // The first group of functions manipulate
  142. // single or small arrays of allocations.
  143. //
  144. virtual bool Delete
  145. (
  146. void *Address,
  147. int Size = NoSize
  148. );
  149. virtual bool Details
  150. (
  151. void *Address,
  152. int *Space = NULL
  153. );
  154. virtual bool KnownArea( void *Address );
  155. virtual bool MultipleDelete
  156. (
  157. int Actual,
  158. void *Array[],
  159. int Size = NoSize
  160. );
  161. virtual bool MultipleNew
  162. (
  163. int *Actual,
  164. void *Array[],
  165. int Requested,
  166. int Size,
  167. int *Space = NULL,
  168. bool Zero = false
  169. );
  170. virtual void *New
  171. (
  172. int Size,
  173. int *Space = NULL,
  174. bool Zero = false
  175. );
  176. virtual void *Resize
  177. (
  178. void *Address,
  179. int NewSize,
  180. int Move = -64,
  181. int *Space = NULL,
  182. bool NoDelete = false,
  183. bool Zero = false
  184. );
  185. virtual bool Verify
  186. (
  187. void *Address = NULL,
  188. int *Space = NULL
  189. );
  190. //
  191. // Manipulate the heap.
  192. //
  193. // The second group of functions act upon a heap
  194. // as a whole.
  195. //
  196. virtual void DeleteAll( bool Recycle = true );
  197. virtual void LockAll( void );
  198. virtual bool Truncate( int MaxFreeSpace = 0 );
  199. virtual void UnlockAll( void );
  200. virtual bool Walk
  201. (
  202. bool *Active,
  203. void **Address,
  204. int *Space
  205. );
  206. //
  207. // Low level heap interface.
  208. //
  209. // The third group of functions are called by the
  210. // heap to aquire or release large blocks of memory.
  211. // These functions can be overloaded to enable the
  212. // heap work in constrained environments.
  213. //
  214. virtual void DeleteArea( void *Memory,int Size,bool User );
  215. virtual int NaturalSize( void );
  216. virtual void *NewArea( int AlignMask,int Size,bool User );
  217. virtual ~ROCKALL( void );
  218. //
  219. // Public inline functions.
  220. //
  221. inline bool Available( void )
  222. { return (GuardWord == GuardValue); }
  223. inline bool Corrupt( void )
  224. { return (GuardWord != GuardValue); }
  225. protected:
  226. //
  227. // Protected inline functions.
  228. //
  229. // A heap needs to compute the size of certain
  230. // user supplied structures. This task is
  231. // performed by the following function.
  232. //
  233. int ComputeSize( char *Array,int Stride );
  234. //
  235. // We would like to allow access to the internal
  236. // heap allocation function from classes that
  237. // inherit from the heap. The memory supplied by
  238. // this function survies all heap operations and
  239. // is cleaned up as poart of heap deletion.
  240. //
  241. virtual void *SpecialNew( int Size );
  242. private:
  243. //
  244. // Disabled operations.
  245. //
  246. // All copy constructors and class assignment
  247. // operations are disabled.
  248. //
  249. ROCKALL( const ROCKALL & Copy );
  250. void operator=( const ROCKALL & Copy );
  251. };
  252. #endif