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.

167 lines
3.6 KiB

  1. //#---------------------------------------------------------------
  2. // File: CPool.h
  3. //
  4. // Synopsis: Header for the CPool class
  5. //
  6. // Copyright (C) 1995 Microsoft Corporation
  7. // All rights reserved.
  8. //
  9. // Authors: HowardCu
  10. //----------------------------------------------------------------
  11. #ifndef _CPOOL_H_
  12. #define _CPOOL_H_
  13. #include "dbgtrace.h"
  14. #define POOL_SIGNATURE (DWORD)'looP'
  15. #define UPSTREAM_SIGNATURE (DWORD)'tspU'
  16. #define DOWNSTREAM_SIGNATURE (DWORD)'tsnD'
  17. #define AUTHENTICATION_SIGNATURE (DWORD)'htuA'
  18. #define USER_SIGNATURE (DWORD)'resU'
  19. #define PROXY_SIGNATURE (DWORD)'xorP'
  20. #define DEFAULT_ALLOC_INCREMENT 0xFFFFFFFF
  21. //
  22. // maximum number of VirtualAlloc chunks to allow
  23. //
  24. #define MAX_CPOOL_FRAGMENTS 16
  25. class CPool
  26. {
  27. //
  28. // struct def'n for linking free instances
  29. // see page 473 of Stroustrup
  30. //
  31. struct Link { Link* pNext; };
  32. public:
  33. CPool( DWORD dwSignature=1 );
  34. ~CPool( void );
  35. void *operator new( size_t cSize )
  36. { return HeapAlloc( GetProcessHeap(), 0, cSize ); }
  37. void operator delete (void *pInstance)
  38. { HeapFree( GetProcessHeap(), 0, pInstance ); }
  39. #ifdef DEBUG
  40. void IsValid( void );
  41. #else
  42. inline void IsValid( void ) { return; }
  43. #endif
  44. //
  45. // to be called after the constructor to VirtualAlloc the necessary
  46. // memory address
  47. //
  48. BOOL ReserveMemory( DWORD MaxInstances,
  49. DWORD InstanceSize,
  50. DWORD IncrementSize = DEFAULT_ALLOC_INCREMENT );
  51. BOOL ReleaseMemory( void );
  52. void* Alloc( void );
  53. void Free( void* pInstance );
  54. DWORD GetContentionCount( void );
  55. DWORD GetEntryCount( void );
  56. DWORD GetTotalAllocCount()
  57. { return m_cTotalAllocs; }
  58. DWORD GetTotalFreeCount()
  59. { return m_cTotalFrees; }
  60. DWORD GetTotalExtraAllocCount()
  61. { return m_cTotalExtraAllocs; }
  62. DWORD GetCommitCount()
  63. { return m_cNumberCommitted; }
  64. DWORD GetAllocCount()
  65. { return m_cNumberInUse; }
  66. DWORD GetInstanceSize(void);
  67. private:
  68. //
  69. // internal function to alloc more mem from the OS
  70. //
  71. void GrowPool( void );
  72. //
  73. // Structure signature for a pool object
  74. //
  75. const DWORD m_dwSignature;
  76. //
  77. // total number of descriptors ( maximum )
  78. //
  79. DWORD m_cMaxInstances;
  80. //
  81. // size of the descriptor
  82. //
  83. DWORD m_cInstanceSize;
  84. //
  85. // virtual array number of committed instances
  86. //
  87. DWORD m_cNumberCommitted;
  88. //
  89. // number of In_use instances ( debug/admin only )
  90. //
  91. DWORD m_cNumberInUse;
  92. //
  93. // number of Free instances ( debug/admin only )
  94. //
  95. DWORD m_cNumberAvail;
  96. //
  97. // the handle of the pool critical section
  98. //
  99. CRITICAL_SECTION m_PoolCriticalSection;
  100. //
  101. // the pointer to the first descriptor on the free list
  102. //
  103. Link *m_pFreeList;
  104. //
  105. // the pointer to a free descriptor not on the free list
  106. //
  107. Link *m_pExtraFreeLink;
  108. //
  109. // number to increment the pool when expanding
  110. //
  111. DWORD m_cIncrementInstances;
  112. //
  113. // Debug counters for perf testing ( debug/admin only )
  114. //
  115. DWORD m_cTotalAllocs;
  116. DWORD m_cTotalFrees;
  117. DWORD m_cTotalExtraAllocs;
  118. //
  119. // Debug variables to help catch heap bugs
  120. //
  121. Link *m_pLastAlloc;
  122. Link *m_pLastExtraAlloc;
  123. //
  124. // size of each fragment in instances
  125. //
  126. DWORD m_cFragmentInstances;
  127. //
  128. // maximum number of fragments
  129. //
  130. DWORD m_cFragments;
  131. //
  132. // maximum number of fragments
  133. //
  134. LPVOID m_pFragments[ MAX_CPOOL_FRAGMENTS ];
  135. };
  136. #endif //!_CPOOL_H_