Use placement new for copy constructor of arrays. Thanks to M. Reuvers for the patch.

http://bulletphysics.com/Bullet/phpBB3/viewforum.php?f=9

Generally, however, it is best to avoid copying entire arrays, but use a 
reference.

typedef btAlignedObjectArray<btSomeClass> Array;

Array a;
Array b = a;//avoid this whenever possible

This is much better:
Array& b = a;//use a reference
const Array& b = a; //or const reference
This commit is contained in:
erwin.coumans 2008-12-08 17:57:18 +00:00
parent f3a70b65eb
commit 65cdd7146f

View File

@ -58,7 +58,7 @@ class btAlignedObjectArray
{
return (size ? size*2 : 1);
}
SIMD_FORCE_INLINE void copy(int start,int end, T* dest)
SIMD_FORCE_INLINE void copy(int start,int end, T* dest) const
{
int i;
for (i=start;i<end;++i)
@ -120,26 +120,21 @@ class btAlignedObjectArray
clear();
}
///Generally it is best to avoid using the copy constructor of an btAlignedObjectArray, and use a (const) reference to the array instead.
btAlignedObjectArray(const btAlignedObjectArray& otherArray)
{
init();
int otherSize = otherArray.size();
resize (otherSize);
int i;
for (i=0;i<otherSize;i++)
{
m_data[i] = otherArray[i];
}
otherArray.copy(0, otherSize, m_data);
}
SIMD_FORCE_INLINE int capacity() const
{ // return current length of allocated storage
return m_capacity;
}
/// return the number of elements in the array
SIMD_FORCE_INLINE int size() const
{ // return length of sequence
{
return m_size;
}
@ -154,6 +149,7 @@ class btAlignedObjectArray
}
///clear the array, deallocated memory. Generally it is better to use array.resize(0), to reduce performance overhead of run-time memory (de)allocations.
SIMD_FORCE_INLINE void clear()
{
destroy(0,size());
@ -169,6 +165,8 @@ class btAlignedObjectArray
m_data[m_size].~T();
}
///resize changes the number of elements in the array. If the new size is larger, the new elements will be constructed using the optional second argument.
///when the new number of elements is smaller, the destructor will be called, but memory will not be freed, to reduce performance overhead of run-time memory (de)allocations.
SIMD_FORCE_INLINE void resize(int newsize, const T& fillData=T())
{
int curSize = size();
@ -232,6 +230,11 @@ class btAlignedObjectArray
}
/// return the pre-allocated (reserved) elements, this is at least as large as the total number of elements,see size() and reserve()
SIMD_FORCE_INLINE int capacity() const
{
return m_capacity;
}
SIMD_FORCE_INLINE void reserve(int _Count)
{ // determine new minimum length of allocated storage