Exemple #1
0
IPoolDataPtr MemoryPool::allocate( const std::size_t size )
{
	// Try to reuse a buffer available in the MemoryPool
	IPoolData* pData = getOneAvailableData( size );
	if( pData != NULL )
	{
		TUTTLE_LOG_TRACE("[Memory Pool] Reuse a buffer available in the MemoryPool");
		pData->setSize( size );
		return pData;
	}

	// Try to remove unused element in MemoryCache, and reuse the buffer available in the MemoryPool
	memory::IMemoryCache& memoryCache = core().getMemoryCache();
	CACHE_ELEMENT unusedCacheElement = memoryCache.getUnusedWithSize( size );
	if( unusedCacheElement.get() != NULL )
	{
		TUTTLE_LOG_TRACE("[Memory Pool] Pop element in the MemoryCache from " << unusedCacheElement->getFullName() << " of size " << size);
		memoryCache.remove( unusedCacheElement );

		pData = getOneAvailableData( size );
		if( pData != NULL )
		{
			TUTTLE_LOG_TRACE("[Memory Pool] Reuse a buffer available in the MemoryPool");
			pData->setSize( size );
			return pData;
		}
	}

	// Try to allocate a new buffer in MemoryPool
	std::size_t availableSize = getAvailableMemorySize();
	if( size > availableSize )
	{
		// Try to release elements from the MemoryCache (make them available to the MemoryPool)
		TUTTLE_LOG_TRACE("[Memory Pool] Release elements from the MemoryCache");
		memoryCache.clearUnused();

		availableSize = getAvailableMemorySize();
		if( size > availableSize )
		{
			// Release elements from the MemoryPool (make them available to the OS)
			TUTTLE_LOG_TRACE("[Memory Pool] Release elements from the MemoryPool");
			clear();
		}

		availableSize = getAvailableMemorySize();
		if( size > availableSize )
		{
			std::stringstream s;
			s << "[Memory Pool] can't allocate size:" << size << " because memory available is equal to " << availableSize << " bytes";
			BOOST_THROW_EXCEPTION( std::length_error( s.str() ) );
		}
	}

	// Allocate a new buffer in MemoryPool
	TUTTLE_TLOG( TUTTLE_TRACE, "[Memory Pool] allocate " << size << " bytes" );
	return new PoolData( *this, size );
}
Exemple #2
0
bool InteractScene::penMotion( const OFX::PenArgs& args )
{
	if( !_mouseDown )
		return false;

	if( _creatingSelection )
	{
		// create selection

		TUTTLE_TLOG( TUTTLE_TRACE, "create a selection" );
		_selectionRect.x2 = args.penPosition.x;
		_selectionRect.y2 = args.penPosition.y;
		_hasSelection = false;

		IsActiveFunctorVector::iterator itActive = _isActive.begin();
		for( InteractObjectsVector::iterator it = _objects.begin(), itEnd = _objects.end();
			 it != itEnd;
			 ++it, ++itActive )
		{
			if( ! itActive->active() )
				continue;
			if( it->isIn( _selectionRect ) )
			{
				it->setSelected(true);
				_hasSelection = true;
			}
			else
			{
				it->setSelected(false);
			}
		}
		return true;
	}

	if( _selected.size() == 0 )
	{
		TUTTLE_LOG_INFOS;
		return false;
	}

	const Point2 penPosition = ofxToGil( args.penPosition );
	switch( _motionType._mode )
	{
		case eMotionTranslate:
		{
			translate( penPosition - _beginPenPosition );
			break;
		}
		case eMotionRotate:
		{
			if( _manipulator )
			{
				rotate( _manipulator->getPosition(), penPosition, penPosition - _beginPenPosition );
			}
			break;
		}
		case eMotionScale:
		{
			if( _manipulator )
				scale( _manipulator->getPosition(), penPosition - _beginPenPosition );
			break;
		}
		case eMotionNone:
		{
			TUTTLE_LOG_INFOS;
			break;
		}
	}
	return true;
}