// EMERGENT GAME TECHNOLOGIES PROPRIETARY INFORMATION // // This software is supplied under the terms of a license agreement or // nondisclosure agreement with Emergent Game Technologies and may not // be copied or disclosed except in accordance with the terms of that // agreement. // // Copyright (c) 1996-2007 Emergent Game Technologies. // All Rights Reserved. // // Emergent Game Technologies, Chapel Hill, North Carolina 27517 // http://www.emergent.net //--------------------------------------------------------------------------- // NiTPointerAllocator inline functions //--------------------------------------------------------------------------- template inline void* NiTPointerAllocator::Allocate() { NiTAbstractPoolAllocator::ms_kCriticalSection.Lock(); #ifdef _DEBUG NiTAbstractPoolAllocator::ms_uiAllocated++; if (NiTAbstractPoolAllocator::ms_uiAllocated > NiTAbstractPoolAllocator::ms_uiMaxAllocated) { NiTAbstractPoolAllocator::ms_uiMaxAllocated = NiTAbstractPoolAllocator::ms_uiAllocated; } #endif if (!NiTAbstractPoolAllocator::ms_pkFreeMem) NiTPointerAllocator::CreateFreeMem(); typename NiTAbstractPoolAllocator::AllocNode* pTmp = NiTAbstractPoolAllocator::ms_pkFreeMem; NiTAbstractPoolAllocator::ms_pkFreeMem = NiTAbstractPoolAllocator::ms_pkFreeMem->m_pkNext; pTmp->m_element = 0; pTmp->m_pkNext = 0; pTmp->m_pkData = 0; NiTAbstractPoolAllocator::ms_kCriticalSection.Unlock(); return pTmp; } //--------------------------------------------------------------------------- template inline void NiTPointerAllocator::Deallocate(void* pkDel) { NiTAbstractPoolAllocator::ms_kCriticalSection.Lock(); #ifdef _DEBUG NiTAbstractPoolAllocator::ms_uiAllocated--; #endif // Node being freed - Just set the freepointer // here and the next to the previous free // In debug, memset(0). typename NiTAbstractPoolAllocator::AllocNode* pDel = (typename NiTAbstractPoolAllocator::AllocNode*)pkDel; pDel->m_pkData = 0; pDel->m_pkNext = NiTAbstractPoolAllocator::ms_pkFreeMem; NiTAbstractPoolAllocator::ms_pkFreeMem = pDel; NiTAbstractPoolAllocator::ms_kCriticalSection.Unlock(); } //---------------------------------------------------------------------------