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.

279 lines
6.9 KiB

  1. /*==========================================================================
  2. *
  3. * Copyright (C) 1998 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: MemoryFPM.h
  6. * Content: Memory Block FPM
  7. *
  8. * History:
  9. * Date By Reason
  10. * ==== == ======
  11. * 01/31/00 mjn Created
  12. ***************************************************************************/
  13. #ifndef __MEMORYFPM_H__
  14. #define __MEMORYFPM_H__
  15. //**********************************************************************
  16. // Constant definitions
  17. //**********************************************************************
  18. #define DN_MEMORY_BLOCK_SIZE_CUSTOM 0
  19. #define DN_MEMORY_BLOCK_SIZE_TINY 128
  20. #define DN_MEMORY_BLOCK_SIZE_SMALL 256
  21. #define DN_MEMORY_BLOCK_SIZE_MEDIUM 512
  22. #define DN_MEMORY_BLOCK_SIZE_LARGE 1024
  23. #define DN_MEMORY_BLOCK_SIZE_HUGE 2048
  24. //**********************************************************************
  25. // Macro definitions
  26. //**********************************************************************
  27. //**********************************************************************
  28. // Structure definitions
  29. //**********************************************************************
  30. typedef struct _DN_MEMORY_BLOCK_HEADER
  31. {
  32. DWORD_PTR dwSize; // Make this DWORD_PTR so it is aligned on 64-bit platforms
  33. } DN_MEMORY_BLOCK_HEADER;
  34. //**********************************************************************
  35. // Variable definitions
  36. //**********************************************************************
  37. //**********************************************************************
  38. // Function prototypes
  39. //**********************************************************************
  40. PVOID MemoryBlockAlloc(void *const pvContext,const DWORD dwSize);
  41. void MemoryBlockFree(void *const pvContext,void *const pvMemoryBlock);
  42. //**********************************************************************
  43. // Class prototypes
  44. //**********************************************************************
  45. // class for TINY memory block
  46. class CMemoryBlockTiny
  47. {
  48. public:
  49. #undef DPF_MODNAME
  50. #define DPF_MODNAME "CMemoryBlockTiny::FPMAlloc"
  51. static BOOL FPMAlloc( void* pvItem, void* pvContext )
  52. {
  53. CMemoryBlockTiny* pMem = (CMemoryBlockTiny*)pvItem;
  54. pMem->m_dwSize = DN_MEMORY_BLOCK_SIZE_TINY;
  55. return(TRUE);
  56. };
  57. DWORD_PTR GetSize(void) const
  58. {
  59. return(m_dwSize);
  60. };
  61. void * GetBuffer(void)
  62. {
  63. return( m_pBuffer );
  64. };
  65. #undef DPF_MODNAME
  66. #define DPF_MODNAME "CMemoryBlockTiny::ReturnSelfToPool"
  67. void ReturnSelfToPool( void )
  68. {
  69. g_MemoryBlockTinyPool.Release(this);
  70. };
  71. static CMemoryBlockTiny *GetObjectFromBuffer( void *const pvBuffer )
  72. {
  73. return( reinterpret_cast<CMemoryBlockTiny*>( &reinterpret_cast<BYTE*>( pvBuffer )[ -OFFSETOF( CMemoryBlockTiny, m_pBuffer ) ] ) );
  74. };
  75. private:
  76. DWORD_PTR m_dwSize; // Make this DWORD_PTR so it is aligned on 64-bit platforms
  77. BYTE m_pBuffer[DN_MEMORY_BLOCK_SIZE_TINY];
  78. };
  79. // class for SMALL memory block
  80. class CMemoryBlockSmall
  81. {
  82. public:
  83. #undef DPF_MODNAME
  84. #define DPF_MODNAME "CMemoryBlockSmall::FPMAlloc"
  85. static BOOL FPMAlloc( void* pvItem, void* pvContext )
  86. {
  87. CMemoryBlockSmall* pMem = (CMemoryBlockSmall*)pvItem;
  88. pMem->m_dwSize = DN_MEMORY_BLOCK_SIZE_SMALL;
  89. return(TRUE);
  90. };
  91. DWORD_PTR GetSize(void) const
  92. {
  93. return(m_dwSize);
  94. };
  95. void * GetBuffer(void)
  96. {
  97. return( m_pBuffer );
  98. };
  99. #undef DPF_MODNAME
  100. #define DPF_MODNAME "CMemoryBlockSmall::ReturnSelfToPool"
  101. void ReturnSelfToPool( void )
  102. {
  103. g_MemoryBlockSmallPool.Release(this);
  104. };
  105. static CMemoryBlockSmall *GetObjectFromBuffer( void *const pvBuffer )
  106. {
  107. return( reinterpret_cast<CMemoryBlockSmall*>( &reinterpret_cast<BYTE*>( pvBuffer )[ -OFFSETOF( CMemoryBlockSmall, m_pBuffer ) ] ) );
  108. };
  109. private:
  110. DWORD_PTR m_dwSize; // Make this DWORD_PTR so it is aligned on 64-bit platforms
  111. BYTE m_pBuffer[DN_MEMORY_BLOCK_SIZE_SMALL];
  112. };
  113. // class for MEDIUM memory block
  114. class CMemoryBlockMedium
  115. {
  116. public:
  117. #undef DPF_MODNAME
  118. #define DPF_MODNAME "CMemoryBlockMedium::FPMAlloc"
  119. static BOOL FPMAlloc( void* pvItem, void* pvContext )
  120. {
  121. CMemoryBlockMedium* pMem = (CMemoryBlockMedium*)pvItem;
  122. pMem->m_dwSize = DN_MEMORY_BLOCK_SIZE_MEDIUM;
  123. return(TRUE);
  124. };
  125. DWORD_PTR GetSize(void) const
  126. {
  127. return(m_dwSize);
  128. };
  129. void * GetBuffer(void)
  130. {
  131. return( m_pBuffer );
  132. };
  133. #undef DPF_MODNAME
  134. #define DPF_MODNAME "CMemoryBlockMedium::ReturnSelfToPool"
  135. void ReturnSelfToPool( void )
  136. {
  137. g_MemoryBlockMediumPool.Release(this);
  138. };
  139. static CMemoryBlockMedium *GetObjectFromBuffer( void *const pvBuffer )
  140. {
  141. return( reinterpret_cast<CMemoryBlockMedium*>( &reinterpret_cast<BYTE*>( pvBuffer )[ -OFFSETOF( CMemoryBlockMedium, m_pBuffer ) ] ) );
  142. };
  143. private:
  144. DWORD_PTR m_dwSize; // Make this DWORD_PTR so it is aligned on 64-bit platforms
  145. BYTE m_pBuffer[DN_MEMORY_BLOCK_SIZE_MEDIUM];
  146. };
  147. // class for LARGE memory block
  148. class CMemoryBlockLarge
  149. {
  150. public:
  151. #undef DPF_MODNAME
  152. #define DPF_MODNAME "CMemoryBlockLarge::FPMAlloc"
  153. static BOOL FPMAlloc( void* pvItem, void* pvContext )
  154. {
  155. CMemoryBlockLarge* pMem = (CMemoryBlockLarge*)pvItem;
  156. pMem->m_dwSize = DN_MEMORY_BLOCK_SIZE_LARGE;
  157. return(TRUE);
  158. };
  159. DWORD_PTR GetSize(void) const
  160. {
  161. return(m_dwSize);
  162. };
  163. void * GetBuffer(void)
  164. {
  165. return( m_pBuffer );
  166. };
  167. #undef DPF_MODNAME
  168. #define DPF_MODNAME "CMemoryBlockLarge::ReturnSelfToPool"
  169. void ReturnSelfToPool( void )
  170. {
  171. g_MemoryBlockLargePool.Release(this);
  172. };
  173. static CMemoryBlockLarge *GetObjectFromBuffer( void *const pvBuffer )
  174. {
  175. return( reinterpret_cast<CMemoryBlockLarge*>( &reinterpret_cast<BYTE*>( pvBuffer )[ -OFFSETOF( CMemoryBlockLarge, m_pBuffer ) ] ) );
  176. };
  177. private:
  178. DWORD_PTR m_dwSize; // Make this DWORD_PTR so it is aligned on 64-bit platforms
  179. BYTE m_pBuffer[DN_MEMORY_BLOCK_SIZE_LARGE];
  180. };
  181. // class for HUGE memory block
  182. class CMemoryBlockHuge
  183. {
  184. public:
  185. #undef DPF_MODNAME
  186. #define DPF_MODNAME "CMemoryBlockHuge::FPMAlloc"
  187. static BOOL FPMAlloc( void* pvItem, void* pvContext )
  188. {
  189. CMemoryBlockHuge* pMem = (CMemoryBlockHuge*)pvItem;
  190. pMem->m_dwSize = DN_MEMORY_BLOCK_SIZE_HUGE;
  191. return(TRUE);
  192. };
  193. DWORD_PTR GetSize(void) const
  194. {
  195. return(m_dwSize);
  196. };
  197. void * GetBuffer(void)
  198. {
  199. return( m_pBuffer );
  200. };
  201. #undef DPF_MODNAME
  202. #define DPF_MODNAME "CMemoryBlockHuge::ReturnSelfToPool"
  203. void ReturnSelfToPool( void )
  204. {
  205. g_MemoryBlockHugePool.Release(this);
  206. };
  207. static CMemoryBlockHuge *GetObjectFromBuffer( void *const pvBuffer )
  208. {
  209. return( reinterpret_cast<CMemoryBlockHuge*>( &reinterpret_cast<BYTE*>( pvBuffer )[ -OFFSETOF( CMemoryBlockHuge, m_pBuffer ) ] ) );
  210. };
  211. private:
  212. DWORD_PTR m_dwSize; // Make this DWORD_PTR so it is aligned on 64-bit platforms
  213. BYTE m_pBuffer[DN_MEMORY_BLOCK_SIZE_HUGE];
  214. };
  215. #undef DPF_MODNAME
  216. #endif // __MEMORYFPM_H__