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:
@@ -58,7 +58,7 @@ class btAlignedObjectArray
|
|||||||
{
|
{
|
||||||
return (size ? size*2 : 1);
|
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;
|
int i;
|
||||||
for (i=start;i<end;++i)
|
for (i=start;i<end;++i)
|
||||||
@@ -120,26 +120,21 @@ class btAlignedObjectArray
|
|||||||
clear();
|
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)
|
btAlignedObjectArray(const btAlignedObjectArray& otherArray)
|
||||||
{
|
{
|
||||||
init();
|
init();
|
||||||
|
|
||||||
int otherSize = otherArray.size();
|
int otherSize = otherArray.size();
|
||||||
resize (otherSize);
|
resize (otherSize);
|
||||||
int i;
|
otherArray.copy(0, otherSize, m_data);
|
||||||
for (i=0;i<otherSize;i++)
|
|
||||||
{
|
|
||||||
m_data[i] = otherArray[i];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
SIMD_FORCE_INLINE int size() const
|
||||||
{ // return length of sequence
|
{
|
||||||
return m_size;
|
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()
|
SIMD_FORCE_INLINE void clear()
|
||||||
{
|
{
|
||||||
destroy(0,size());
|
destroy(0,size());
|
||||||
@@ -169,6 +165,8 @@ class btAlignedObjectArray
|
|||||||
m_data[m_size].~T();
|
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())
|
SIMD_FORCE_INLINE void resize(int newsize, const T& fillData=T())
|
||||||
{
|
{
|
||||||
int curSize = size();
|
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)
|
SIMD_FORCE_INLINE void reserve(int _Count)
|
||||||
{ // determine new minimum length of allocated storage
|
{ // determine new minimum length of allocated storage
|
||||||
|
|||||||
Reference in New Issue
Block a user