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.

123 lines
2.0 KiB

  1. /*++
  2. Copyright (c) 1994 Microsoft Corporation
  3. All rights reserved.
  4. Module Name:
  5. memblock.hxx
  6. Abstract:
  7. Memory allocater for chunks of read only memory header.
  8. Author:
  9. Albert Ting (AlbertT) 30-Aug-1994
  10. Revision History:
  11. --*/
  12. #ifndef _MEMBLOCK_HXX
  13. #define _MEMBLOCK_HXX
  14. class TMemBlock {
  15. SIGNATURE( 'memb' )
  16. ALWAYS_VALID
  17. SAFE_NEW
  18. public:
  19. enum _CONSTANTS {
  20. kFlagGlobalNew = 0x1
  21. };
  22. TMemBlock(
  23. UINT uGranularity,
  24. DWORD fdwFlags
  25. );
  26. ~TMemBlock(
  27. VOID
  28. );
  29. PVOID
  30. pvAlloc(
  31. DWORD dwSize
  32. );
  33. PVOID
  34. pvFirst(
  35. VOID
  36. );
  37. PVOID
  38. pvIter(
  39. VOID
  40. );
  41. UINT
  42. uSize(
  43. PVOID pvUser
  44. ) const;
  45. private:
  46. typedef struct _DATA {
  47. DWORD dwSize;
  48. DWORD dwPadding;
  49. } DATA, *PDATA;
  50. typedef struct _BLOCK {
  51. struct _BLOCK* pNext;
  52. PDATA pDataLast;
  53. } BLOCK, *PBLOCK;
  54. PBLOCK _pFirst;
  55. PBLOCK _pLast;
  56. DWORD _uGranularity;
  57. DWORD _dwNextFree;
  58. DWORD _dwCount;
  59. PDATA _pDataLast;
  60. DWORD _dwIterCount;
  61. PBLOCK _pIterBlock;
  62. PDATA _pIterData;
  63. DWORD _fdwFlags;
  64. DWORD
  65. dwBlockHeaderSize(
  66. VOID
  67. ) const
  68. { return DWordAlign(sizeof(BLOCK)); }
  69. PDATA
  70. pBlockToData(
  71. PBLOCK pBlock
  72. ) const
  73. { return (PDATA)((PBYTE)pBlock + dwBlockHeaderSize()); }
  74. DWORD
  75. dwDataHeaderSize(
  76. VOID
  77. ) const
  78. { return DWordAlign(sizeof(DATA)); }
  79. PVOID
  80. pvDataToUser(
  81. PDATA pData
  82. ) const
  83. { return (PVOID)((PBYTE)pData + dwDataHeaderSize()); }
  84. PDATA
  85. pvUserToData(
  86. PVOID pvUser
  87. ) const
  88. { return (PDATA)((PBYTE)pvUser - dwDataHeaderSize()); }
  89. PDATA
  90. pDataNext(
  91. PDATA pData
  92. ) const
  93. { return (PDATA) ((PBYTE)pData + pData->dwSize); }
  94. };
  95. #endif // ndef _MEMBLOCK_HXX