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.

80 lines
2.1 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows NT **/
  3. /** Copyright(c) Microsoft Corp., 1997 **/
  4. /**********************************************************************/
  5. /*
  6. manodel.hxx
  7. This module contains the definitions for a memory allocation class that doesn't
  8. delete memory until the class goes away.
  9. FILE HISTORY:
  10. 1/9/98 michth created
  11. */
  12. #ifndef _MANODEL_HXX_
  13. #define _MANODEL_HXX_
  14. #include <irtlmisc.h>
  15. #define USE_PROCESS_HEAP 0
  16. #define DEFAULT_MIN_BLOCK_MULTIPLE 3
  17. #define MAX_BLOCK_MULTIPLE 10
  18. #define BLOCK_HEADER_SIZE sizeof(PVOID)
  19. #define GREATER_OF(P1, P2) (((P1) >= (P2)) ? (P1) : (P2))
  20. #define LESSER_OF(P1, P2) (((P1) <= (P2)) ? (P1) : (P2))
  21. class IRTL_DLLEXP MEMORY_ALLOC_NO_DELETE;
  22. class IRTL_DLLEXP MEMORY_ALLOC_NO_DELETE
  23. {
  24. public:
  25. MEMORY_ALLOC_NO_DELETE( DWORD dwAllocSize,
  26. DWORD dwAlignment = 4,
  27. BOOL bSortFree = FALSE,
  28. DWORD dwMinBlockMultiple = DEFAULT_MIN_BLOCK_MULTIPLE,
  29. HANDLE hHeap = USE_PROCESS_HEAP);
  30. ~MEMORY_ALLOC_NO_DELETE();
  31. PVOID Alloc();
  32. BOOL Free (PVOID pvMem);
  33. private:
  34. DWORD m_dwAllocSize;
  35. DWORD m_dwBlockMultiple;
  36. HANDLE m_hHeap;
  37. DWORD m_dwNumAlloced;
  38. DWORD m_dwNumFree;
  39. DWORD m_dwNumBlocks;
  40. DWORD m_dwBlockHeaderSpace;
  41. DWORD m_dwMaxBlockMultiple;
  42. DWORD m_dwAlignment;
  43. DWORD m_dwAlignBytes;
  44. BOOL m_bSortFree;
  45. PVOID m_pvBlockList;
  46. PVOID m_pvFreeList;
  47. CRITICAL_SECTION m_csLock;
  48. VOID GetNewBlockMultiple();
  49. PVOID GetAllocFromFreeList();
  50. BOOL AllocBlock();
  51. VOID AddBlockToFreeList(PVOID pvNewBlock);
  52. VOID LockThis( VOID ) { EnterCriticalSection(&m_csLock);}
  53. VOID UnlockThis( VOID ) { LeaveCriticalSection(&m_csLock);}
  54. VOID AlignAdjust(DWORD &rdwSize, DWORD dwAlignment);
  55. #ifdef _WIN64
  56. VOID AlignAdjust(ULONG_PTR &rSize, ULONG_PTR Alignment);
  57. #endif
  58. };
  59. #endif // !_MANODEL_