Page 1 of 1

Should I replace std::vector with btAlignedObjectArray?

Posted: Wed Oct 11, 2017 5:15 am
by 123iamking
I see description of btAlignedObjectArray class
.\bullet3\src\LinearMath\btAlignedObjectArray.h

The btAlignedObjectArray template class uses a subset of the stl::vector interface for its methods
It is developed to replace stl::vector to avoid portability issues, including STL alignment issues to add SIMD/SSE data
I see that stl and std are difference.

But I confuse why Bullet don't use std::vector (std::vector is really optimized) instead of creating btAlignedObjectArray class, maybe there is a reason so I don't know if I should use std::vector instead of btAlignedObjectArray?

Thanks for reading :D

Re: Should I replace std::vector with btAlignedObjectArray?

Posted: Wed Oct 11, 2017 1:43 pm
by drleviathan
The reason Bullet uses btAlignedObjectArray is right there in that comment you found: to avoid portability issues and to support SIMD/SSE data. SIMD data blocks (128 bits) must be 16-byte aligned, otherwise the optimized instructions won't work.

If you want to make an array of btVector3, btTransform, or other Bullet classes that take advantage of SIMD optimizations, you would want to use btAlignedObjectArray. For other data (your own classes that don't derive from Bullet classes) you can safely use std::vector.

Re: Should I replace std::vector with btAlignedObjectArray?

Posted: Thu Oct 12, 2017 1:26 pm
by 123iamking
drleviathan wrote:The reason Bullet uses btAlignedObjectArray is right there in that comment you found: to avoid portability issues and to support SIMD/SSE data. SIMD data blocks (128 bits) must be 16-byte aligned, otherwise the optimized instructions won't work.

If you want to make an array of btVector3, btTransform, or other Bullet classes that take advantage of SIMD optimizations, you would want to use btAlignedObjectArray. For other data (your own classes that don't derive from Bullet classes) you can safely use std::vector.
Thank drleviathan :) So as I understand, btAlignedObjectArray is mean for Bullet internal use (optimize Bullet purpose). The client code can use std::vector instead of btAlignedObjectArray.