Пример #1
0
//-----------------------------------------------------------------------------
// Makes sure we've got at least this much memory
//-----------------------------------------------------------------------------
void CUtlMemoryBase::EnsureCapacity( int num )
{
	if (m_nAllocationCount >= num)
		return;

	if ( IsExternallyAllocated() )
	{
		// Can't grow a buffer whose memory was externally allocated 
		Assert(0);
		return;
	}

	UTLMEMORY_TRACK_FREE();

	m_nAllocationCount = num;

	UTLMEMORY_TRACK_ALLOC();

	if (m_pMemory)
	{
		m_pMemory = PvRealloc( m_pMemory, m_nAllocationCount * m_unSizeOfElements );
	}
	else
	{
		m_pMemory = PvAlloc( m_nAllocationCount * m_unSizeOfElements );
	}
}
Пример #2
0
void CUtlMemoryBase::Grow( int num )
{
	Assert( num > 0 );

	if ( IsExternallyAllocated() )
	{
		// Can't grow a buffer whose memory was externally allocated 
		Assert(0);
		return;
	}

	// Make sure we have at least numallocated + num allocations.
	// Use the grow rules specified for this memory (in m_nGrowSize)
	int nAllocationRequested = m_nAllocationCount + num;

	UTLMEMORY_TRACK_FREE();

	m_nAllocationCount = UtlMemory_CalcNewAllocationCount( m_nAllocationCount, m_nGrowSize, nAllocationRequested, m_unSizeOfElements );

	UTLMEMORY_TRACK_ALLOC();
	if (m_pMemory)
	{
		m_pMemory = PvRealloc( m_pMemory, m_nAllocationCount * m_unSizeOfElements );
	}
	else
	{
		m_pMemory = PvAlloc( m_nAllocationCount * m_unSizeOfElements );
	}
}
Пример #3
0
//-----------------------------------------------------------------------------
// Sets the priority level for a spew group
//-----------------------------------------------------------------------------
void SpewActivate( const tchar* pGroupName, int level )
{
	Assert( pGroupName );
	
	// check for the default group first...
	if ((pGroupName[0] == '*') && (pGroupName[1] == '\0'))
	{
		s_DefaultLevel = level;
		return;
	}
	
	// Normal case, search in group list using binary search.
	// If not found, grow the list of groups and insert it into the
	// right place to maintain sorted order. Then set the level.
	int ind;
	if ( !FindSpewGroup( pGroupName, &ind ) )
	{
		// not defined yet, insert an entry.
		++s_GroupCount;
		if ( s_pSpewGroups )
		{
			s_pSpewGroups = (SpewGroup_t*)PvRealloc( s_pSpewGroups, 
				s_GroupCount * sizeof(SpewGroup_t) );
			
			// shift elements down to preserve order
			int numToMove = s_GroupCount - ind - 1;
			memmove( &s_pSpewGroups[ind+1], &s_pSpewGroups[ind], 
				numToMove * sizeof(SpewGroup_t) );

			// Update standard groups
			for ( int i = 0; i < GROUP_COUNT; ++i )
			{   
				if ( ( ind <= s_pGroupIndices[i] ) && ( s_pGroupIndices[i] >= 0 ) )
				{
					++s_pGroupIndices[i];
				}
			}
		}
		else
		{
			s_pSpewGroups = (SpewGroup_t*)PvAlloc( s_GroupCount * sizeof(SpewGroup_t) ); 
		}
		
		Assert( _tcslen( pGroupName ) < MAX_GROUP_NAME_LENGTH );
		_tcscpy( s_pSpewGroups[ind].m_GroupName, pGroupName );

		// Update standard groups
		for ( int i = 0; i < GROUP_COUNT; ++i )
		{
			if ( ( s_pGroupIndices[i] < 0 ) && !_tcsicmp( s_pGroupNames[i], pGroupName ) )
			{
				s_pGroupIndices[i] = ind;
				break;
			}
		}
	}
	s_pSpewGroups[ind].m_Level = level;
}
Пример #4
0
CUtlMemoryBase::CUtlMemoryBase( int nSizeOfType, int nGrowSize, int nInitAllocationCount ) : m_pMemory(0), 
m_nAllocationCount( nInitAllocationCount ), m_nGrowSize( nGrowSize ), m_unSizeOfElements( nSizeOfType )
{
	Assert( m_unSizeOfElements > 0 );
	Assert( nGrowSize >= 0 );
	if (m_nAllocationCount)
	{
		UTLMEMORY_TRACK_ALLOC();
		m_pMemory = PvAlloc( m_nAllocationCount * m_unSizeOfElements );
	}
}
Пример #5
0
//-----------------------------------------------------------------------------
// Switches the buffer from an external memory buffer to a reallocatable buffer
//-----------------------------------------------------------------------------
void CUtlMemoryBase::ConvertToGrowableMemory( int nGrowSize )
{
	if ( !IsExternallyAllocated() )
		return;

	m_nGrowSize = nGrowSize;
	if (m_nAllocationCount)
	{
		UTLMEMORY_TRACK_ALLOC();
		MEM_ALLOC_CREDIT_CLASS();

		int nNumBytes = m_nAllocationCount * m_unSizeOfElements;
		void *pMemory = PvAlloc( nNumBytes );
		memcpy( pMemory, m_pMemory, nNumBytes ); 
		m_pMemory = pMemory;
	}
	else
	{
		m_pMemory = NULL;
	}
}
Пример #6
0
CVSEG *
PcvsegMapPmod(PMOD pmod, WORD *pccvseg, PIMAGE pimage)
// Generates a list of CVSEG's for the specified module (one for each
// contiguous region of some segment).
//
// NOTE: we do not attempt to merge CVSEG's (we just add new CON's at
// the beginning or end) so out-of-order CON's may cause extra CVSEG's
// to be created (and therefore the sstSrcModule might be larger than
// necessary).  I think this will happen only if -order is being used.
//
{
    ENM_SRC enmSrc;
    CVSEG *pcvsegHead;

    pcvsegHead = NULL;
    *pccvseg = 0;

    for (InitEnmSrc(&enmSrc, pmod); FNextEnmSrc(&enmSrc); ) {
        CVSEG *pcvsegPrev;
        CVSEG *pcvsegNext;
        CVSEG *pcvsegNew;

        if (enmSrc.pcon->flags & IMAGE_SCN_LNK_REMOVE) {
            continue;
        }

        if (enmSrc.pcon->cbRawData == 0) {
            continue;
        }

        if (PsecPCON(enmSrc.pcon) == psecDebug) {
            continue;
        }

        if (pimage->Switch.Link.fTCE) {
            if (FDiscardPCON_TCE(enmSrc.pcon)) {
                // Discarded comdat

                continue;
            }
        }

        // Find location of this CON in linked list sorted by RVA.

        pcvsegPrev = NULL;

        for (pcvsegNext = pcvsegHead;
             pcvsegNext != NULL;
             pcvsegNext = pcvsegNext->pcvsegNext) {
              if (pcvsegNext->pconFirst->rva > enmSrc.pcon->rva) {
                 break;
              }

              pcvsegPrev = pcvsegNext;
        }

        if (FetchContent(PsecPCON(enmSrc.pcon)->flags) == IMAGE_SCN_CNT_CODE) {
            // Check if we can combine with adjacent CVSEG.

            if ((pcvsegPrev != NULL) &&
                (pcvsegPrev->pconLast->pconNext == enmSrc.pcon)) {
                // New CON follows existing CVSEG.  Extend forward.

                pcvsegPrev->pconLast = enmSrc.pcon;
                continue;
            }

            if ((pcvsegNext != NULL) &&
                (pcvsegNext->pconFirst == enmSrc.pcon->pconNext)) {
                // New CON preceeds existing CVSEG.  Extend backward.

                pcvsegNext->pconFirst = enmSrc.pcon;
                continue;
            }
        }

        pcvsegNew = (CVSEG *) PvAlloc(sizeof(CVSEG));

        pcvsegNew->pgrp = enmSrc.pcon->pgrpBack;
        pcvsegNew->pconFirst = pcvsegNew->pconLast = enmSrc.pcon;

        pcvsegNew->pcvsegNext = pcvsegNext;

        if (pcvsegPrev != NULL) {
            pcvsegPrev->pcvsegNext = pcvsegNew;
        } else {
            pcvsegHead = pcvsegNew;
        }

        (*pccvseg)++;
    }

    return(pcvsegHead);
}