Source code of Windows XP (NT5)
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.

275 lines
8.3 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_LINKAGE __declspec(dllexport)
  57. #else
  58. #define ROCKALL_LINKAGE __declspec(dllimport)
  59. #endif
  60. /********************************************************************/
  61. /* */
  62. /* The memory allocation interface. */
  63. /* */
  64. /* The memory allocator can be configured in a wide variety */
  65. /* of ways to closely match the needs of specific programs. */
  66. /* The interface outlined here can be overloaded to support */
  67. /* whatever customization is necessary. */
  68. /* */
  69. /********************************************************************/
  70. class ROCKALL_LINKAGE ROCKALL
  71. {
  72. public:
  73. //
  74. // Public types.
  75. //
  76. // A heap is constructed of a collection of
  77. // fixed sized buckets each with an associated
  78. // cache. The details of these buckets are
  79. // supplied to the heap using the following
  80. // structure.
  81. //
  82. typedef struct
  83. {
  84. int AllocationSize;
  85. int CacheSize;
  86. int ChunkSize;
  87. int PageSize;
  88. }
  89. CACHE_DETAILS;
  90. //
  91. // Public data.
  92. //
  93. // The internals linkages in a heap are built
  94. // dynamically during the execution of a heaps
  95. // constructor. The member that follow relate
  96. // to key internal classes.
  97. //
  98. CACHE **Array;
  99. CACHE *Caches;
  100. FIND *Find;
  101. HEAP *Heap;
  102. NEW_PAGE *NewPage;
  103. //
  104. // A heap constructor is required to preserve
  105. // a small amount of information for the heap
  106. // destructor.
  107. //
  108. bool GlobalDelete;
  109. int GuardWord;
  110. int NumberOfCaches;
  111. int TotalSize;
  112. //
  113. // Public functions.
  114. //
  115. // A heaps public interface consists of a number
  116. // of groups of related APIs.
  117. //
  118. ROCKALL( void );
  119. ROCKALL
  120. (
  121. CACHE_DETAILS *Caches1,
  122. CACHE_DETAILS *Caches2,
  123. int FindCacheSize,
  124. int FindCacheThreshold,
  125. int FindSize,
  126. int MaxFreeSpace,
  127. int *NewPageSizes,
  128. bool Recycle,
  129. bool SingleImage,
  130. int Stride1,
  131. int Stride2,
  132. bool ThreadSafe
  133. );
  134. //
  135. // Manipulate allocations.
  136. //
  137. // The first group of functions manipulate
  138. // single or small arrays of allocations.
  139. //
  140. virtual bool Delete
  141. (
  142. void *Address,
  143. int Size = NoSize
  144. );
  145. virtual bool Details
  146. (
  147. void *Address,
  148. int *Space = NULL
  149. );
  150. virtual bool KnownArea( void *Address );
  151. virtual bool MultipleDelete
  152. (
  153. int Actual,
  154. void *Array[],
  155. int Size = NoSize
  156. );
  157. virtual bool MultipleNew
  158. (
  159. int *Actual,
  160. void *Array[],
  161. int Requested,
  162. int Size,
  163. int *Space = NULL,
  164. bool Zero = false
  165. );
  166. virtual void *New
  167. (
  168. int Size,
  169. int *Space = NULL,
  170. bool Zero = false
  171. );
  172. virtual void *Resize
  173. (
  174. void *Address,
  175. int NewSize,
  176. int Move = -64,
  177. int *Space = NULL,
  178. bool NoDelete = false,
  179. bool Zero = false
  180. );
  181. virtual bool Verify
  182. (
  183. void *Address = NULL,
  184. int *Space = NULL
  185. );
  186. //
  187. // Manipulate the heap.
  188. //
  189. // The second group of functions act upon a heap
  190. // as a whole.
  191. //
  192. virtual void DeleteAll( bool Recycle = true );
  193. virtual void LockAll( void );
  194. virtual void Truncate( int MaxFreeSpace = 0 );
  195. virtual void UnlockAll( void );
  196. virtual bool Walk
  197. (
  198. bool *Active,
  199. void **Address,
  200. int *Space
  201. );
  202. //
  203. // Low level heap interface.
  204. //
  205. // The third group of functions are called by the
  206. // heap to aquire or release large blocks of memory.
  207. // These functions can be overloaded to enable the
  208. // heap work in constrained environments.
  209. //
  210. virtual void DeleteArea( void *Memory,int Size );
  211. virtual int NaturalSize( void );
  212. virtual void *NewArea( int AlignMask,int Size );
  213. virtual ~ROCKALL( void );
  214. //
  215. // Public inline functions.
  216. //
  217. inline bool Available( void )
  218. { return (GuardWord == GuardValue); }
  219. inline bool Failure( void )
  220. { return (GuardWord != GuardValue); }
  221. private:
  222. //
  223. // Private functions.
  224. //
  225. // A heap needs to compute the size of certain
  226. // user supplied structures. This task is
  227. // performed by the following function.
  228. //
  229. int ComputeSize( char *Array,int Stride );
  230. //
  231. // Disabled operations.
  232. //
  233. // All copy constructors and class assignment
  234. // operations are disabled.
  235. //
  236. ROCKALL( const ROCKALL & Copy );
  237. void operator=( const ROCKALL & Copy );
  238. };
  239. #endif