mirror of
https://github.com/bulletphysics/bullet3
synced 2024-12-16 14:40:05 +00:00
parallel solver: slightly overallocate to reduce how often allocation is needed
This commit is contained in:
parent
eec478709a
commit
e526e48df8
@ -892,6 +892,12 @@ static void setupSpatialGridBatchesMt(
|
||||
memHelper.addChunk( (void**) &constraintBatchIds, sizeof( int ) * numConstraints );
|
||||
memHelper.addChunk( (void**) &constraintRowBatchIds, sizeof( int ) * numConstraintRows );
|
||||
size_t scratchSize = memHelper.getSizeToAllocate();
|
||||
// if we need to reallocate
|
||||
if (scratchMemory->capacity() < scratchSize)
|
||||
{
|
||||
// allocate 6.25% extra to avoid repeated reallocs
|
||||
scratchMemory->reserve( scratchSize + scratchSize/16 );
|
||||
}
|
||||
scratchMemory->resizeNoInitialize( scratchSize );
|
||||
char* memPtr = &scratchMemory->at(0);
|
||||
memHelper.setChunkPointers( memPtr );
|
||||
|
@ -568,10 +568,22 @@ void btSequentialImpulseConstraintSolverMt::allocAllContactConstraints(btPersist
|
||||
}
|
||||
}
|
||||
}
|
||||
m_tmpSolverContactConstraintPool.resizeNoInitialize(numContacts);
|
||||
m_rollingFrictionIndexTable.resizeNoInitialize(numContacts);
|
||||
m_tmpSolverContactFrictionConstraintPool.resizeNoInitialize(numContacts*m_numFrictionDirections);
|
||||
m_tmpSolverContactRollingFrictionConstraintPool.resizeNoInitialize(numRollingFrictionConstraints);
|
||||
{
|
||||
BT_PROFILE( "allocPools" );
|
||||
if ( m_tmpSolverContactConstraintPool.capacity() < numContacts )
|
||||
{
|
||||
// if we need to reallocate, reserve some extra so we don't have to reallocate again next frame
|
||||
int extraReserve = numContacts / 16;
|
||||
m_tmpSolverContactConstraintPool.reserve( numContacts + extraReserve );
|
||||
m_rollingFrictionIndexTable.reserve( numContacts + extraReserve );
|
||||
m_tmpSolverContactFrictionConstraintPool.reserve( ( numContacts + extraReserve )*m_numFrictionDirections );
|
||||
m_tmpSolverContactRollingFrictionConstraintPool.reserve( numRollingFrictionConstraints + extraReserve );
|
||||
}
|
||||
m_tmpSolverContactConstraintPool.resizeNoInitialize( numContacts );
|
||||
m_rollingFrictionIndexTable.resizeNoInitialize( numContacts );
|
||||
m_tmpSolverContactFrictionConstraintPool.resizeNoInitialize( numContacts*m_numFrictionDirections );
|
||||
m_tmpSolverContactRollingFrictionConstraintPool.resizeNoInitialize( numRollingFrictionConstraints );
|
||||
}
|
||||
}
|
||||
{
|
||||
AllocContactConstraintsLoop loop(this, &cachedInfoArray[0]);
|
||||
|
Loading…
Reference in New Issue
Block a user