Changeset 37
- Timestamp:
- Nov 7, 2011, 2:00:04 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Utilities/VirtualHeapPtr/VirtualHeapPtr.h
r36 r37 138 138 { 139 139 public: 140 static SIZE_T g_nHeadSanityPageCount;141 static SIZE_T g_nTailSanityPageCount;142 143 public:144 140 // CDebugAllocatorTraits 145 }; 146 147 __declspec(selectany) SIZE_T CDebugAllocatorTraits::g_nHeadSanityPageCount = 1; 148 __declspec(selectany) SIZE_T CDebugAllocatorTraits::g_nTailSanityPageCount = 1; 141 static SIZE_T GetHeadSanityPageCount() throw() 142 { 143 return 1; 144 } 145 static SIZE_T GetTailSanityPageCount() throw() 146 { 147 return 1; 148 } 149 static BOOL IsHeadPadding() throw() 150 { 151 return TRUE; 152 } 153 }; 149 154 150 155 //////////////////////////////////////////////////////////// … … 178 183 const SIZE_T nAllocationSize = 179 184 g_GlobalVirtualAllocator.Align(sizeof (CDescriptor)) + 180 CTraits:: g_nHeadSanityPageCount* nPageSize +185 CTraits::GetHeadSanityPageCount() * nPageSize + 181 186 nAlignedDataSize + 182 CTraits:: g_nTailSanityPageCount* nPageSize +187 CTraits::GetTailSanityPageCount() * nPageSize + 183 188 0; 184 189 VOID* pvData = VirtualAlloc(NULL, nAllocationSize, MEM_COMMIT | MEM_RESERVE, PAGE_NOACCESS); … … 188 193 ATLVERIFY(VirtualProtect(pDescriptor, sizeof *pDescriptor, PAGE_READWRITE, &nCurrentProtection)); 189 194 pDescriptor->m_nAllocationSize = nAllocationSize; 190 pDescriptor->m_pvData = (BYTE*) pDescriptor + g_GlobalVirtualAllocator.Align(sizeof *pDescriptor) + CTraits:: g_nHeadSanityPageCount* nPageSize;195 pDescriptor->m_pvData = (BYTE*) pDescriptor + g_GlobalVirtualAllocator.Align(sizeof *pDescriptor) + CTraits::GetHeadSanityPageCount() * nPageSize; 191 196 pDescriptor->m_nDataSize = nDataSize; 192 pDescriptor->m_nPaddingDataSize = nAlignedDataSize - nDataSize; 193 pDescriptor->m_pvPaddingData = (BYTE*) pDescriptor->m_pvData + nAlignedDataSize - pDescriptor->m_nPaddingDataSize; 197 const SIZE_T nPaddingDataSize = nAlignedDataSize - nDataSize; 198 if(CTraits::IsHeadPadding() && nPaddingDataSize) 199 { 200 pDescriptor->m_pvPaddingData = pDescriptor->m_pvData; 201 reinterpret_cast<BYTE*&>(pDescriptor->m_pvData) += nPaddingDataSize; 202 } else 203 pDescriptor->m_pvPaddingData = (BYTE*) pDescriptor->m_pvData + nAlignedDataSize - nPaddingDataSize; 204 pDescriptor->m_nPaddingDataSize = nPaddingDataSize; 194 205 ATLVERIFY(VirtualProtect(pDescriptor->m_pvData, pDescriptor->m_nDataSize, PAGE_READWRITE, &nCurrentProtection)); 195 206 memset(pDescriptor->m_pvPaddingData, 0x77, pDescriptor->m_nPaddingDataSize); … … 200 211 { 201 212 ATLASSERT(pvData); 202 CDescriptor* pDescriptor = (CDescriptor*) ((BYTE*) pvData - CTraits::g_nHeadSanityPageCount * g_GlobalVirtualAllocator.GetPageSize() - g_GlobalVirtualAllocator.Align(sizeof (CDescriptor))); 213 ATLASSERT(!(g_GlobalVirtualAllocator.GetPageSize() & (g_GlobalVirtualAllocator.GetPageSize() - 1))); 214 BYTE* pnData = (BYTE*) ((UINT_PTR) pvData & ~(g_GlobalVirtualAllocator.GetPageSize() - 1)); 215 CDescriptor* pDescriptor = (CDescriptor*) (pnData - CTraits::GetHeadSanityPageCount() * g_GlobalVirtualAllocator.GetPageSize() - g_GlobalVirtualAllocator.Align(sizeof (CDescriptor))); 203 216 return pDescriptor; 204 217 }
Note: See TracChangeset
for help on using the changeset viewer.