Esempio n. 1
0
		// -------------------------------------------------------------------------------------------------------
		void* AllocatorMT::Alloc( SizeT size )
		{
			UInt32 threadID = (UInt32)GetCurrentThreadId();
			MemPool* pool = FindPool(threadID);
			if (pool == 0)
			{
				CreatePool(threadID);
				pool = FindPool(threadID);
				A_ASSERT(pool != 0, "Unable to create pool for this thread!");
			}
			
			return pool->Alloc(size);
		}
Esempio n. 2
0
void *CSmallBlockHeap::Realloc( void *p, size_t nBytes )
{
	if ( nBytes == 0)
	{
		nBytes = 1;
	}

	CSmallBlockPool *pOldPool = FindPool( p );
	CSmallBlockPool *pNewPool = ( ShouldUse( nBytes ) ) ? FindPool( nBytes ) : NULL;

	if ( pOldPool == pNewPool )
	{
		return p;
	}

	void *pNewBlock = NULL;

	if ( pNewPool )
	{
		pNewBlock = pNewPool->Alloc();

		if ( !pNewBlock )
		{
			if ( s_StdMemAlloc.CallAllocFailHandler( nBytes ) >= nBytes )
			{
				pNewBlock = pNewPool->Alloc();
			}
		}
	}

	if ( !pNewBlock )
	{
		pNewBlock = malloc( nBytes );
		if ( !pNewBlock )
		{
			s_StdMemAlloc.SetCRTAllocFailed( nBytes );
		}
	}

	if ( pNewBlock )
	{
		int nBytesCopy = min( nBytes, pOldPool->GetBlockSize() );
		memcpy( pNewBlock, p, nBytesCopy );
	}

	pOldPool->Free( p );

	return pNewBlock;
}
Esempio n. 3
0
	void unsynchronized_pool_resource::do_deallocate(void * p, size_type bytes, size_type alignment) noexcept
	{
		auto finalSize = Internal::GetFinalSize(bytes, alignment);
		if (finalSize > maxBlockSize_) return poolManager_.Deallocate(p);
		const auto poolIndex = FindPool(bytes);
		pools_[poolIndex].Deallocate(p);
	}
Esempio n. 4
0
void *CSmallBlockHeap::Alloc( size_t nBytes )
{
	if ( nBytes == 0)
	{
		nBytes = 1;
	}
	Assert( ShouldUse( nBytes ) );
	CSmallBlockPool *pPool = FindPool( nBytes );
	
	void *p = pPool->Alloc();
	if ( p )
	{
		return p;
	}

	if ( s_StdMemAlloc.CallAllocFailHandler( nBytes ) >= nBytes )
	{
		p = pPool->Alloc();
		if ( p )
		{
			return p;
		}
	}

	void *pRet = malloc( nBytes );
	if ( !pRet )
	{
		s_StdMemAlloc.SetCRTAllocFailed( nBytes );
	}
	return pRet;
}
Esempio n. 5
0
		// -------------------------------------------------------------------------------------------------------
		Bool AllocatorMT::Free( void* ptr )
		{
			UInt32 threadID = (UInt32)GetCurrentThreadId();
			MemPool* pool = FindPool(threadID);
			A_ASSERT(pool != 0, "Try to free a pointer which not in this thread!");
			return pool->Free(ptr);
		}
Esempio n. 6
0
	void* unsynchronized_pool_resource::do_allocate(size_type bytes, size_type alignment)
	{
		const auto finalSize = Internal::GetFinalSize(bytes, alignment);
		if (finalSize > maxBlockSize_)
		{
			return poolManager_.Allocate(bytes, alignment);
		}
		const auto poolIndex = FindPool(bytes);
		return pools_[poolIndex].Allocate(bytes, alignment);
	}
Esempio n. 7
0
void *CX360SmallBlockHeap::Realloc( void *p, size_t nBytes )
{
	if ( nBytes == 0)
	{
		nBytes = 1;
	}

	CX360SmallBlockPool *pOldPool = FindPool( p );
	CX360SmallBlockPool *pNewPool = ( ShouldUse( nBytes ) ) ? FindPool( nBytes ) : NULL;

	if ( pOldPool == pNewPool )
	{
		return p;
	}

	void *pNewBlock = NULL;

	if ( pNewPool )
	{
		pNewBlock = pNewPool->Alloc();

		if ( !pNewBlock )
		{
			pNewBlock = GetStandardSBH()->Alloc( nBytes );
		}
	}

	if ( !pNewBlock )
	{
		pNewBlock = malloc( nBytes );
	}

	if ( pNewBlock )
	{
		int nBytesCopy = min( nBytes, pOldPool->GetBlockSize() );
		memcpy( pNewBlock, p, nBytesCopy );
	}

	pOldPool->Free( p );

	return pNewBlock;
}
Esempio n. 8
0
void *CX360SmallBlockHeap::Alloc( size_t nBytes )
{
	if ( nBytes == 0)
	{
		nBytes = 1;
	}
	Assert( ShouldUse( nBytes ) );
	CX360SmallBlockPool *pPool = FindPool( nBytes );

	void *p = pPool->Alloc();
	if ( p )
	{
		return p;
	}

	return GetStandardSBH()->Alloc( nBytes );
}
Esempio n. 9
0
		// -------------------------------------------------------------------------------------------------------
		Bool AllocatorMT::CreatePool( UInt32 threadID )
		{
			EnterCriticalSection(&mCriticalSection);

			Bool result = 0;
			if(FindPool(threadID) == 0)
			{
				A_ASSERT(mPoolCount < MaxThreadCount, "Try to create pools over max number limits");
				mThreadIDs[mPoolCount] = threadID;
				mMemPools[mPoolCount] = new MemPool();
				++mPoolCount;
				result = true;
			}
			else
			{
				result = false;
			}

			LeaveCriticalSection(&mCriticalSection);

			return result;
		}
Esempio n. 10
0
size_t CX360SmallBlockHeap::GetSize( void *p )
{
	CX360SmallBlockPool *pPool = FindPool( p );
	return pPool->GetBlockSize();
}
Esempio n. 11
0
void CX360SmallBlockHeap::Free( void *p )
{
	CX360SmallBlockPool *pPool = FindPool( p );
	pPool->Free( p );
}
Esempio n. 12
0
bool CX360SmallBlockPool::IsOwner( void *p )
{
	return ( FindPool( p ) == this );
}