Thunderbrd
C2C War Dog
Turn Taken. Praetyre is up!
template <class T>
T* FFreeListTrashArray<T>::add()
{
int iIndex;
T* result = NULL;
EnterCriticalSection(&m_cModifySection);
if (m_pArray == NULL)
{
init();
}
if ((m_iLastIndex == m_iNumSlots - 1) &&
(m_iFreeListCount == 0))
{
if ((m_iNumSlots * FLTA_GROWTH_FACTOR) > FLTA_MAX_BUCKETS)
{
LeaveCriticalSection(&m_cModifySection);
return NULL;
}
growArray();
}
if (m_iFreeListCount > 0)
{
m_iFreeListCount--;
int iLast = FFreeList::INVALID_INDEX;
iIndex = m_iFreeListHead;
// Ttry to choose a free node that is not from the current major id space so as
// to minimize the rate we move through the global id space
while( iIndex != FFreeList::INVALID_INDEX && m_pArray[iIndex].iLastUsed == m_iCurrentID)
{
iLast = iIndex;
iIndex = m_pArray[iIndex].iNextFreeIndex;
}
@Koshling:
This is where the problem lies:
That while loop... m_pArray[iIndex].iLastUsed is always == m_iCurrentID (1990656). That does NOT strike me as right. Then again, the whole system seems... baffling.Code:template <class T> T* FFreeListTrashArray<T>::add() { int iIndex; T* result = NULL; EnterCriticalSection(&m_cModifySection); if (m_pArray == NULL) { init(); } if ((m_iLastIndex == m_iNumSlots - 1) && (m_iFreeListCount == 0)) { if ((m_iNumSlots * FLTA_GROWTH_FACTOR) > FLTA_MAX_BUCKETS) { LeaveCriticalSection(&m_cModifySection); return NULL; } growArray(); } if (m_iFreeListCount > 0) { m_iFreeListCount--; int iLast = FFreeList::INVALID_INDEX; iIndex = m_iFreeListHead; // Ttry to choose a free node that is not from the current major id space so as // to minimize the rate we move through the global id space while( iIndex != FFreeList::INVALID_INDEX && m_pArray[iIndex].iLastUsed == m_iCurrentID) { iLast = iIndex; iIndex = m_pArray[iIndex].iNextFreeIndex; }
if (m_iFreeListCount > 0)
{
m_iFreeListCount--;
int iLast = FFreeList::INVALID_INDEX;
iIndex = m_iFreeListHead;
// Ttry to choose a free node that is not from the current major id space so as
// to minimize the rate we move through the global id space
while( iIndex != FFreeList::INVALID_INDEX && m_pArray[iIndex].iLastUsed == m_iCurrentID)
while( iIndex != FFreeList::INVALID_INDEX && m_pArray[iIndex].iLastUsed == m_iCurrentID)
{
iLast = iIndex;
iIndex = m_pArray[iIndex].iNextFreeIndex;
}
template <class T>
T* FFreeListTrashArray<T>::add()
{
int iIndex;
T* result = NULL;
EnterCriticalSection(&m_cModifySection);
if (m_pArray == NULL)
{
init();
}
if ((m_iLastIndex == m_iNumSlots - 1) &&
(m_iFreeListCount == 0))
{
if ((m_iNumSlots * FLTA_GROWTH_FACTOR) > FLTA_MAX_BUCKETS)
{
LeaveCriticalSection(&m_cModifySection);
return NULL;
}
growArray();
}
if (m_iFreeListCount > 0)
{
m_iFreeListCount--;
int iLast = FFreeList::INVALID_INDEX;
iIndex = m_iFreeListHead;
// Ttry to choose a free node that is not from the current major id space so as
// to minimize the rate we move through the global id space
while( iIndex != FFreeList::INVALID_INDEX && m_pArray[iIndex].iLastUsed == m_iCurrentID)
{
iLast = iIndex;
iIndex = m_pArray[iIndex].iNextFreeIndex;
}
if ( iIndex == FFreeList::INVALID_INDEX )
{
// Didn't find one - just take the free list head node
iIndex = m_iFreeListHead;
m_iFreeListHead = m_pArray[iIndex].iNextFreeIndex;
}
else
{
// Foudn one - take it out of the middle of the free list
if ( iLast == FFreeList::INVALID_INDEX )
{
m_iFreeListHead = m_pArray[iIndex].iNextFreeIndex;
}
else
{
m_pArray[iLast].iNextFreeIndex = m_pArray[iIndex].iNextFreeIndex;
}
}
}
else
{
m_iLastIndex++;
iIndex = m_iLastIndex;
}
MEMORY_TRACK_EXEMPT();
m_pArray[iIndex].pData = new T;
m_pArray[iIndex].iNextFreeIndex = FFreeList::INVALID_INDEX;
if ( m_pArray[iIndex].iLastUsed == m_iCurrentID )
{
m_iCurrentID += FLTA_MAX_BUCKETS;
}
m_pArray[iIndex].pData->setID(m_iCurrentID + iIndex);
m_pArray[iIndex].iLastUsed = m_iCurrentID;
result = m_pArray[iIndex].pData;
LeaveCriticalSection(&m_cModifySection);
return result;
}