Changeset 37 for trunk


Ignore:
Timestamp:
Nov 7, 2011, 2:00:04 AM (12 years ago)
Author:
roman
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Utilities/VirtualHeapPtr/VirtualHeapPtr.h

    r36 r37  
    138138{
    139139public:
    140         static SIZE_T g_nHeadSanityPageCount;
    141         static SIZE_T g_nTailSanityPageCount;
    142 
    143 public:
    144140// 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};
    149154
    150155////////////////////////////////////////////////////////////
     
    178183                        const SIZE_T nAllocationSize =
    179184                                g_GlobalVirtualAllocator.Align(sizeof (CDescriptor)) +
    180                                 CTraits::g_nHeadSanityPageCount * nPageSize +
     185                                CTraits::GetHeadSanityPageCount() * nPageSize +
    181186                                nAlignedDataSize +
    182                                 CTraits::g_nTailSanityPageCount * nPageSize +
     187                                CTraits::GetTailSanityPageCount() * nPageSize +
    183188                                0;
    184189                        VOID* pvData = VirtualAlloc(NULL, nAllocationSize, MEM_COMMIT | MEM_RESERVE, PAGE_NOACCESS);
     
    188193                        ATLVERIFY(VirtualProtect(pDescriptor, sizeof *pDescriptor, PAGE_READWRITE, &nCurrentProtection));
    189194                        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;
    191196                        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;
    194205                        ATLVERIFY(VirtualProtect(pDescriptor->m_pvData, pDescriptor->m_nDataSize, PAGE_READWRITE, &nCurrentProtection));
    195206                        memset(pDescriptor->m_pvPaddingData, 0x77, pDescriptor->m_nPaddingDataSize);
     
    200211                {
    201212                        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)));
    203216                        return pDescriptor;
    204217                }
Note: See TracChangeset for help on using the changeset viewer.