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.

188 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 "BlendedHeap.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 = 4096;
  35. CONST SBIT32 FindCacheThreshold = 0;
  36. CONST SBIT32 FindSize = 2048;
  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, 64, 32, 512 },
  60. { 8, 32, 32, 512 },
  61. { 12, 32, 64, 512 },
  62. { 16, 16, 64, 512 },
  63. { 20, 16, 64, 512 },
  64. { 24, 12, 96, 512 },
  65. { 32, 12, 128, 512 },
  66. { 40, 8, 128, 512 },
  67. { 48, 8, 256, 512 },
  68. { 64, 8, 256, 512 },
  69. { 80, 4, 512, 512 },
  70. { 96, 4, 512, 512 },
  71. { 128, 4, 4096, 4096 },
  72. { 160, 4, 4096, 4096 },
  73. { 192, 4, 4096, 4096 },
  74. { 224, 4, 4096, 4096 },
  75. { 256, 4, 4096, 4096 },
  76. { 320, 2, 4096, 4096 },
  77. { 384, 2, 4096, 4096 },
  78. { 448, 2, 4096, 4096 },
  79. { 512, 2, 4096, 4096 },
  80. { 640, 0, 8192, 8192 },
  81. { 704, 0, 4096, 4096 },
  82. { 768, 0, 4096, 4096 },
  83. { 832, 0, 8192, 8192 },
  84. { 896, 0, 8192, 8192 },
  85. { 960, 0, 4096, 4096 },
  86. { 0,0,0,0 }
  87. };
  88. STATIC ROCKALL::CACHE_DETAILS Caches2[] =
  89. {
  90. //
  91. // Bucket Size Of Bucket Parent
  92. // Size Cache Chunks Page Size
  93. //
  94. { 1024, 2, 4096, 4096 },
  95. { 2048, 2, 4096, 4096 },
  96. { 3072, 0, 65536, 65536 },
  97. { 4096, 0, 65536, 65536 },
  98. { 5120, 0, 65536, 65536 },
  99. { 6144, 0, 65536, 65536 },
  100. { 7168, 0, 65536, 65536 },
  101. { 8192, 0, 65536, 65536 },
  102. { 9216, 0, 65536, 65536 },
  103. { 10240, 0, 65536, 65536 },
  104. { 12288, 0, 65536, 65536 },
  105. { 16384, 0, 65536, 65536 },
  106. { 21504, 0, 65536, 65536 },
  107. { 32768, 0, 65536, 65536 },
  108. { 65536, 0, 65536, 65536 },
  109. { 65536, 0, 65536, 65536 },
  110. { 0,0,0,0 }
  111. };
  112. /********************************************************************/
  113. /* */
  114. /* The description bit vectors. */
  115. /* */
  116. /* All heaps keep track of allocations using bit vectors. An */
  117. /* allocation requires 2 bits to keep track of its state. The */
  118. /* following array supplies the size of the available bit */
  119. /* vectors measured in 32 bit words. */
  120. /* */
  121. /********************************************************************/
  122. STATIC int NewPageSizes[] = { 1,4,16,0 };
  123. /********************************************************************/
  124. /* */
  125. /* Class constructor. */
  126. /* */
  127. /* The overall structure and layout of the heap is controlled */
  128. /* by the various constants and calls made in this function. */
  129. /* There is a significant amount of flexibility available to */
  130. /* a heap which can lead to them having dramatically different */
  131. /* properties. */
  132. /* */
  133. /********************************************************************/
  134. BLENDED_HEAP::BLENDED_HEAP
  135. (
  136. int MaxFreeSpace,
  137. bool Recycle,
  138. bool SingleImage,
  139. bool ThreadSafe
  140. ) :
  141. //
  142. // Call the constructors for the contained classes.
  143. //
  144. ROCKALL
  145. (
  146. Caches1,
  147. Caches2,
  148. FindCacheSize,
  149. FindCacheThreshold,
  150. FindSize,
  151. MaxFreeSpace,
  152. NewPageSizes,
  153. Recycle,
  154. SingleImage,
  155. Stride1,
  156. Stride2,
  157. ThreadSafe
  158. )
  159. { /* void */ }
  160. /********************************************************************/
  161. /* */
  162. /* Class destructor. */
  163. /* */
  164. /* Destory the heap. */
  165. /* */
  166. /********************************************************************/
  167. BLENDED_HEAP::~BLENDED_HEAP( VOID )
  168. { /* void */ }