2 Bullet Continuous Collision Detection and Physics Library
3 Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
5 This software is provided 'as-is', without any express or implied warranty.
6 In no event will the authors be held liable for any damages arising from the use of this software.
7 Permission is granted to anyone to use this software for any purpose,
8 including commercial applications, and to alter it and redistribute it freely,
9 subject to the following restrictions:
11 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
12 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
13 3. This notice may not be removed or altered from any source distribution.
17 #ifndef BT_OBJECT_ARRAY__
18 #define BT_OBJECT_ARRAY__
20 #include "btScalar.h" // has definitions like SIMD_FORCE_INLINE
21 #include "btAlignedAllocator.h"
23 ///btAlignedObjectArray uses a subset of the stl::vector interface for its methods
24 ///It is developed to replace stl::vector to avoid STL alignment issues to add SIMD/SSE data
27 class btAlignedObjectArray
33 btAlignedAllocator<T , 16> m_allocator;
36 SIMD_FORCE_INLINE int allocSize(int size)
38 return (size ? size*2 : 1);
40 SIMD_FORCE_INLINE void copy(int start,int end, T* dest)
43 for (i=0;i<m_size;++i)
47 SIMD_FORCE_INLINE void init()
53 SIMD_FORCE_INLINE void destroy(int first,int last)
56 for (i=0; i<m_size;i++)
62 SIMD_FORCE_INLINE void* allocate(int size)
65 return m_allocator.allocate(size);
69 SIMD_FORCE_INLINE void deallocate()
72 m_allocator.deallocate(m_data);
78 btAlignedObjectArray()
83 ~btAlignedObjectArray()
88 SIMD_FORCE_INLINE int capacity() const
89 { // return current length of allocated storage
93 SIMD_FORCE_INLINE int size() const
94 { // return length of sequence
98 SIMD_FORCE_INLINE const T& operator[](int n) const
103 SIMD_FORCE_INLINE T& operator[](int n)
109 SIMD_FORCE_INLINE void clear()
118 SIMD_FORCE_INLINE void pop_back()
124 SIMD_FORCE_INLINE void resize(int newsize)
126 if (newsize > size())
136 SIMD_FORCE_INLINE void push_back(const T& _Val)
139 if( sz == capacity() )
141 reserve( allocSize(size()) );
144 m_data[size()] = _Val;
145 //::new ( m_data[m_size] ) T(_Val);
151 SIMD_FORCE_INLINE void reserve(int _Count)
152 { // determine new minimum length of allocated storage
153 if (capacity() < _Count)
154 { // not enough room, reallocate
155 if (capacity() < _Count)
157 T* s = (T*)allocate(_Count);
175 #endif //BT_OBJECT_ARRAY__