Beispiel #1
0
void CMemoryStack::FreeToAllocPoint( MemoryStackMark_t mark )
{
    void *pAllocPoint = m_pBase + mark;
    Assert( pAllocPoint >= m_pBase && pAllocPoint <= m_pNextAlloc );

    if ( pAllocPoint >= m_pBase && pAllocPoint < m_pNextAlloc )
    {
#if defined(_WIN32)
        unsigned char *pDecommitPoint = MemAlign( (unsigned char *)pAllocPoint, m_commitSize );

        if ( pDecommitPoint < m_pBase + m_minCommit )
        {
            pDecommitPoint = m_pBase + m_minCommit;
        }

        unsigned decommitSize = m_pCommitLimit - pDecommitPoint;

        if ( decommitSize > 0 )
        {
            MemAlloc_RegisterExternalDeallocation( CMemoryStack, GetBase(), GetSize() );

            VirtualFree( pDecommitPoint, decommitSize, MEM_DECOMMIT );
            m_pCommitLimit = pDecommitPoint;

            if ( mark > 0 )
            {
                MemAlloc_RegisterExternalAllocation( CMemoryStack, GetBase(), GetSize() );
            }
        }
#endif
        m_pNextAlloc = (unsigned char *)pAllocPoint;
    }
}
void XMemAlloc_RegisterDeallocation( void *p, DWORD dwAllocAttributes )
{
	if ( !g_pMemAlloc )
	{
		// core xallocs cannot be journaled until system is ready
		return;
	}

	AUTO_LOCK_FM( g_XMemAllocMutex );
	int size = XMemSize( p, dwAllocAttributes );
	MemAlloc_RegisterExternalDeallocation( XMem, p, size );
}
Beispiel #3
0
void CMemoryStack::FreeAll()
{
    if ( m_pBase && m_pCommitLimit - m_pBase > 0 )
    {
#if defined(_WIN32)
        MemAlloc_RegisterExternalDeallocation( CMemoryStack, GetBase(), GetSize() );

        VirtualFree( m_pBase, m_pCommitLimit - m_pBase, MEM_DECOMMIT );
        m_pCommitLimit = m_pBase;
#endif
        m_pNextAlloc = m_pBase;
    }
}
Beispiel #4
0
void *CMemoryStack::Alloc( unsigned bytes, const char *pszName )
{
    Assert( m_pBase );

    if ( !bytes )
        bytes = 1;

    bytes = MemAlign( bytes, m_alignment );

    void *pResult = m_pNextAlloc;
    m_pNextAlloc += bytes;

    if ( m_pNextAlloc > m_pCommitLimit )
    {
#if defined(_WIN32)
        unsigned char *	pNewCommitLimit = MemAlign( m_pNextAlloc, m_commitSize );
        unsigned 		commitSize 		= pNewCommitLimit - m_pCommitLimit;

        MemAlloc_RegisterExternalDeallocation( CMemoryStack, GetBase(), GetSize() );

        Assert( m_pCommitLimit + commitSize < m_pAllocLimit );
        if ( !VirtualAlloc( m_pCommitLimit, commitSize, VA_COMMIT_FLAGS, PAGE_READWRITE ) )
        {
            Assert( 0 );
            return NULL;
        }
        m_pCommitLimit = pNewCommitLimit;

        MemAlloc_RegisterExternalAllocation( CMemoryStack, GetBase(), GetSize() );
#else
        Assert( 0 );
        return NULL;
#endif
    }

    memset( pResult, 0, bytes );

    return pResult;
}