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.

189 lines
8.6 KiB

  1. // Ruler
  2. // 1 2 3 4 5 6 7 8
  3. //345678901234567890123456789012345678901234567890123456789012345678901234567890
  4. /********************************************************************/
  5. /* */
  6. /* The standard layout. */
  7. /* */
  8. /* The standard layout for 'cpp' files in this code is as */
  9. /* follows: */
  10. /* */
  11. /* 1. Include files. */
  12. /* 2. Constants local to the class. */
  13. /* 3. Data structures local to the class. */
  14. /* 4. Data initializations. */
  15. /* 5. Static functions. */
  16. /* 6. Class functions. */
  17. /* */
  18. /* The constructor is typically the first function, class */
  19. /* member functions appear in alphabetical order with the */
  20. /* destructor appearing at the end of the file. Any section */
  21. /* or function this is not required is simply omitted. */
  22. /* */
  23. /********************************************************************/
  24. #include "InterfacePCH.hpp"
  25. #include "FastHeap.hpp"
  26. /********************************************************************/
  27. /* */
  28. /* Constants local to the class. */
  29. /* */
  30. /* The constants supplied here try to make the layout of the */
  31. /* the caches easier to understand and update. */
  32. /* */
  33. /********************************************************************/
  34. CONST SBIT32 FindCacheSize = 8192;
  35. CONST SBIT32 FindCacheThreshold = 0;
  36. CONST SBIT32 FindSize = 4096;
  37. CONST SBIT32 Stride1 = 4;
  38. CONST SBIT32 Stride2 = 1024;
  39. /********************************************************************/
  40. /* */
  41. /* The description of the heap. */
  42. /* */
  43. /* A heap is a collection of fixed sized allocation caches. */
  44. /* An allocation cache consists of an allocation size, the */
  45. /* number of pre-built allocations to cache, a chunk size and */
  46. /* a parent page size which is sub-divided to create elements */
  47. /* for this cache. A heap consists of two arrays of caches. */
  48. /* Each of these arrays has a stride (i.e. 'Stride1' and */
  49. /* 'Stride2') which is typically the smallest common factor of */
  50. /* all the allocation sizes in the array. */
  51. /* */
  52. /********************************************************************/
  53. STATIC ROCKALL::CACHE_DETAILS Caches1[] =
  54. {
  55. //
  56. // Bucket Size Of Bucket Parent
  57. // Size Cache Chunks Page Size
  58. //
  59. { 4, 256, 32, 4096 },
  60. { 8, 128, 32, 4096 },
  61. { 12, 128, 64, 4096 },
  62. { 16, 128, 64, 4096 },
  63. { 20, 64, 64, 4096 },
  64. { 24, 64, 96, 4096 },
  65. { 32, 64, 128, 4096 },
  66. { 40, 64, 128, 4096 },
  67. { 48, 64, 256, 4096 },
  68. { 64, 64, 256, 4096 },
  69. { 80, 64, 512, 4096 },
  70. { 96, 64, 512, 4096 },
  71. { 128, 32, 4096, 4096 },
  72. { 160, 16, 4096, 4096 },
  73. { 192, 16, 4096, 4096 },
  74. { 224, 16, 4096, 4096 },
  75. { 256, 16, 4096, 4096 },
  76. { 320, 8, 4096, 4096 },
  77. { 384, 8, 4096, 4096 },
  78. { 448, 8, 4096, 4096 },
  79. { 512, 4, 4096, 4096 },
  80. { 576, 4, 4096, 4096 },
  81. { 640, 4, 8192, 8192 },
  82. { 704, 4, 4096, 4096 },
  83. { 768, 4, 4096, 4096 },
  84. { 832, 4, 8192, 8192 },
  85. { 896, 4, 8192, 8192 },
  86. { 960, 4, 4096, 4096 },
  87. { 0,0,0,0 }
  88. };
  89. STATIC ROCKALL::CACHE_DETAILS Caches2[] =
  90. {
  91. //
  92. // Bucket Size Of Bucket Parent
  93. // Size Cache Chunks Page Size
  94. //
  95. { 1024, 16, 4096, 4096 },
  96. { 2048, 16, 4096, 4096 },
  97. { 3072, 4, 65536, 65536 },
  98. { 4096, 8, 65536, 65536 },
  99. { 5120, 4, 65536, 65536 },
  100. { 6144, 4, 65536, 65536 },
  101. { 7168, 4, 65536, 65536 },
  102. { 8192, 8, 65536, 65536 },
  103. { 9216, 0, 65536, 65536 },
  104. { 10240, 0, 65536, 65536 },
  105. { 12288, 0, 65536, 65536 },
  106. { 16384, 2, 65536, 65536 },
  107. { 21504, 0, 65536, 65536 },
  108. { 32768, 0, 65536, 65536 },
  109. { 65536, 0, 65536, 65536 },
  110. { 65536, 0, 65536, 65536 },
  111. { 0,0,0,0 }
  112. };
  113. /********************************************************************/
  114. /* */
  115. /* The description bit vectors. */
  116. /* */
  117. /* All heaps keep track of allocations using bit vectors. An */
  118. /* allocation requires 2 bits to keep track of its state. The */
  119. /* following array supplies the size of the available bit */
  120. /* vectors measured in 32 bit words. */
  121. /* */
  122. /********************************************************************/
  123. STATIC int NewPageSizes[] = { 1,4,16,64,0 };
  124. /********************************************************************/
  125. /* */
  126. /* Class constructor. */
  127. /* */
  128. /* The overall structure and layout of the heap is controlled */
  129. /* by the various constants and calls made in this function. */
  130. /* There is a significant amount of flexibility available to */
  131. /* a heap which can lead to them having dramatically different */
  132. /* properties. */
  133. /* */
  134. /********************************************************************/
  135. FAST_HEAP::FAST_HEAP
  136. (
  137. int MaxFreeSpace,
  138. bool Recycle,
  139. bool SingleImage,
  140. bool ThreadSafe
  141. ) :
  142. //
  143. // Call the constructors for the contained classes.
  144. //
  145. ROCKALL
  146. (
  147. Caches1,
  148. Caches2,
  149. FindCacheSize,
  150. FindCacheThreshold,
  151. FindSize,
  152. MaxFreeSpace,
  153. NewPageSizes,
  154. Recycle,
  155. SingleImage,
  156. Stride1,
  157. Stride2,
  158. ThreadSafe
  159. )
  160. { /* void */ }
  161. /********************************************************************/
  162. /* */
  163. /* Class destructor. */
  164. /* */
  165. /* Destory the heap. */
  166. /* */
  167. /********************************************************************/
  168. FAST_HEAP::~FAST_HEAP( VOID )
  169. { /* void */ }