Should I replace std::vector with btAlignedObjectArray?

Post Reply
123iamking
Posts: 10
Joined: Wed Oct 11, 2017 4:45 am

Should I replace std::vector with btAlignedObjectArray?

Post 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
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

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

Post 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.
123iamking
Posts: 10
Joined: Wed Oct 11, 2017 4:45 am

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

Post 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.
Post Reply