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 "SmallHeap.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 = 2048;
  35. CONST SBIT32 FindCacheThreshold = 0;
  36. CONST SBIT32 FindSize = 1024;
  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, 0, 32, 32 },
  60. { 8, 0, 32, 32 },
  61. { 12, 0, 64, 64 },
  62. { 16, 0, 64, 64 },
  63. { 20, 0, 64, 64 },
  64. { 24, 0, 128, 128 },
  65. { 32, 0, 64, 64 },
  66. { 40, 0, 128, 128 },
  67. { 48, 0, 256, 256 },
  68. { 64, 0, 128, 128 },
  69. { 80, 0, 512, 512 },
  70. { 96, 0, 512, 512 },
  71. { 128, 0, 256, 256 },
  72. { 160, 0, 512, 512 },
  73. { 192, 0, 1024, 1024 },
  74. { 224, 0, 512, 512 },
  75. { 256, 0, 512, 512 },
  76. { 320, 0, 1024, 1024 },
  77. { 384, 0, 2048, 2048 },
  78. { 448, 0, 4096, 4096 },
  79. { 512, 0, 1024, 1024 },
  80. { 576, 0, 4096, 4096 },
  81. { 640, 0, 8192, 8192 },
  82. { 704, 0, 4096, 4096 },
  83. { 768, 0, 4096, 4096 },
  84. { 832, 0, 8192, 8192 },
  85. { 896, 0, 8192, 8192 },
  86. { 960, 0, 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, 0, 2048, 2048 },
  96. { 2048, 0, 4096, 4096 },
  97. { 3072, 0, 65536, 65536 },
  98. { 4096, 0, 8192, 8192 },
  99. { 5120, 0, 65536, 65536 },
  100. { 6144, 0, 65536, 65536 },
  101. { 7168, 0, 65536, 65536 },
  102. { 8192, 0, 65536, 65536 },
  103. { 9216, 0, 65536, 65536 },
  104. { 10240, 0, 65536, 65536 },
  105. { 12288, 0, 65536, 65536 },
  106. { 16384, 0, 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,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. SMALL_HEAP::SMALL_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. SMALL_HEAP::~SMALL_HEAP( VOID )
  169. { /* void */ }