Ejemplo n.º 1
0
//-----------------------------------------------------------------------------
//	XMemAlloc
//
//	XBox Memory Allocator Override
//-----------------------------------------------------------------------------
LPVOID WINAPI XMemAlloc( SIZE_T dwSize, DWORD dwAllocAttributes )
{
	LPVOID	ptr;
	XALLOC_ATTRIBUTES *pAttribs = (XALLOC_ATTRIBUTES *)&dwAllocAttributes;
	bool bPhysical = ( pAttribs->dwMemoryType == XALLOC_MEMTYPE_PHYSICAL );

	if ( !bPhysical && !pAttribs->dwHeapTracksAttributes && pAttribs->dwAllocatorId != eXALLOCAllocatorId_XUI )
	{
		MEM_ALLOC_CREDIT();
		switch ( pAttribs->dwAlignment )
		{
		case XALLOC_ALIGNMENT_4:
#if !defined(USE_LIGHT_MEM_DEBUG) && !defined(USE_MEM_DEBUG)
			ptr = MemAlloc_Alloc( dwSize );
#else
			ptr = MemAlloc_Alloc(dwSize, g_pszModule, 0);
#endif
			break;
		case XALLOC_ALIGNMENT_8:
			ptr = MemAlloc_AllocAligned( dwSize, 8 );
			break;
		case XALLOC_ALIGNMENT_DEFAULT:
		case XALLOC_ALIGNMENT_16:
		default:
			ptr = MemAlloc_AllocAligned( dwSize, 16 );
			break;
		}
		if ( pAttribs->dwZeroInitialize != 0 )
		{
			memset( ptr, 0, XMemSize( ptr, dwAllocAttributes ) );
		}
		return ptr;
	}

	ptr = XMemAllocDefault( dwSize, dwAllocAttributes );
	if ( ptr )
	{
		XMemAlloc_RegisterAllocation( ptr, dwAllocAttributes );
	}

	return ptr;
}
void CLightingManager::AllocateSortDataBuffer()
{
	if( m_pSortDataX4 != NULL )
	{
		MemAlloc_FreeAligned( m_pSortDataX4 );
		m_pSortDataX4 = NULL;
	}

	if( m_hDeferredLights.Count() == 0 )
		return;

	const int iSortBufferDataSize = m_hDeferredLights.Count() % 4 == 0
			? m_hDeferredLights.Count() / 4 
			: ((m_hDeferredLights.Count() - (m_hDeferredLights.Count() % 4)) / 4) + 1;

	m_pSortDataX4 = reinterpret_cast<def_light_presortdatax4_t*>(
		MemAlloc_AllocAligned( iSortBufferDataSize * sizeof(def_light_presortdatax4_t),
		sizeof(fltx4) ));
}
Ejemplo n.º 3
0
// aligned base
ALLOC_CALL void *__cdecl _aligned_malloc_base( size_t size, size_t align )
{
	return MemAlloc_AllocAligned( size, align );
}
Ejemplo n.º 4
0
bool CMemoryStack::Init( unsigned maxSize, unsigned commitSize, unsigned initialCommit, unsigned alignment )
{
	Assert( !m_pBase );

#ifdef _X360
	m_bPhysical = false;
#endif

	m_maxSize = maxSize;
	m_alignment = AlignValue( alignment, 4 );

	Assert( m_alignment == alignment );
	Assert( m_maxSize > 0 );

#if defined(_WIN32)
	if ( commitSize != 0 )
	{
		m_commitSize = commitSize;
	}

	unsigned pageSize;

#ifndef _X360
	SYSTEM_INFO sysInfo;
	GetSystemInfo( &sysInfo );
	Assert( !( sysInfo.dwPageSize & (sysInfo.dwPageSize-1)) );
	pageSize = sysInfo.dwPageSize;
#else
	pageSize = 64*1024;
#endif

	if ( m_commitSize == 0 )
	{
		m_commitSize = pageSize;
	}
	else
	{
		m_commitSize = AlignValue( m_commitSize, pageSize );
	}

	m_maxSize = AlignValue( m_maxSize, m_commitSize );
	
	Assert( m_maxSize % pageSize == 0 && m_commitSize % pageSize == 0 && m_commitSize <= m_maxSize );

	m_pBase = (unsigned char *)VirtualAlloc( NULL, m_maxSize, VA_RESERVE_FLAGS, PAGE_NOACCESS );
	Assert( m_pBase );
	m_pCommitLimit = m_pNextAlloc = m_pBase;

	if ( initialCommit )
	{
		initialCommit = AlignValue( initialCommit, m_commitSize );
		Assert( initialCommit < m_maxSize );
		if ( !VirtualAlloc( m_pCommitLimit, initialCommit, VA_COMMIT_FLAGS, PAGE_READWRITE ) )
			return false;
		m_minCommit = initialCommit;
		m_pCommitLimit += initialCommit;
		MemAlloc_RegisterExternalAllocation( CMemoryStack, GetBase(), GetSize() );
	}

#else
	m_pBase = (byte *)MemAlloc_AllocAligned( m_maxSize, alignment ? alignment : 1 );
	m_pNextAlloc = m_pBase;
	m_pCommitLimit = m_pBase + m_maxSize;
#endif

	m_pAllocLimit = m_pBase + m_maxSize;

	return ( m_pBase != NULL );
}