mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-07-18 10:54:26 +08:00
remove ei_new_allocator
remove corresponding part of test_dynalloc
This commit is contained in:
parent
335d3bcf05
commit
3efe6e4176
@ -313,10 +313,10 @@ struct WithAlignedOperatorNew
|
|||||||
*
|
*
|
||||||
* Example:
|
* Example:
|
||||||
* \code
|
* \code
|
||||||
* // Vector4f requires 16 bytes alignment:
|
* // Matrix4f requires 16 bytes alignment:
|
||||||
* std::vector<Vector4f, aligned_allocator<Vector4f> > dataVec4;
|
* std::map< int, Matrix4f, std::less<int>, aligned_allocator<Matrix4f> > my_map_mat4;
|
||||||
* // Vector3f does not require 16 bytes alignment, no need to use Eigen's allocator:
|
* // Vector3f does not require 16 bytes alignment, no need to use Eigen's allocator:
|
||||||
* std::vector<Vector3f> dataVec3;
|
* std::map< int, Vector3f > my_map_vec3;
|
||||||
* \endcode
|
* \endcode
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@ -392,51 +392,4 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/** \class ei_new_allocator
|
|
||||||
*
|
|
||||||
* \brief stl compatible allocator to use with with fixed-size vector and matrix types
|
|
||||||
*
|
|
||||||
* STL allocator simply wrapping operators new[] and delete[]. Unlike GCC's default new_allocator,
|
|
||||||
* ei_new_allocator call operator new on the type \a T and not the general new operator ignoring
|
|
||||||
* overloaded version of operator new.
|
|
||||||
*
|
|
||||||
* Example:
|
|
||||||
* \code
|
|
||||||
* // Vector4f requires 16 bytes alignment:
|
|
||||||
* std::vector<Vector4f,ei_new_allocator<Vector4f> > dataVec4;
|
|
||||||
* // Vector3f does not require 16 bytes alignment, no need to use Eigen's allocator:
|
|
||||||
* std::vector<Vector3f> dataVec3;
|
|
||||||
*
|
|
||||||
* struct Foo : WithAlignedOperatorNew {
|
|
||||||
* char dummy;
|
|
||||||
* Vector4f some_vector;
|
|
||||||
* };
|
|
||||||
* std::vector<Foo,ei_new_allocator<Foo> > dataFoo;
|
|
||||||
* \endcode
|
|
||||||
*
|
|
||||||
* \sa class WithAlignedOperatorNew
|
|
||||||
*/
|
|
||||||
template<typename T> class ei_new_allocator
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
typedef T value_type;
|
|
||||||
typedef T* pointer;
|
|
||||||
typedef const T* const_pointer;
|
|
||||||
typedef T& reference;
|
|
||||||
typedef const T& const_reference;
|
|
||||||
|
|
||||||
template<typename OtherType>
|
|
||||||
struct rebind
|
|
||||||
{ typedef ei_new_allocator<OtherType> other; };
|
|
||||||
|
|
||||||
T* address(T& ref) const { return &ref; }
|
|
||||||
const T* address(const T& ref) const { return &ref; }
|
|
||||||
T* allocate(size_t size, const void* = 0) { return new T[size]; }
|
|
||||||
void deallocate(T* ptr, size_t) { delete[] ptr; }
|
|
||||||
size_t max_size() const { return size_t(-1) / sizeof(T); }
|
|
||||||
// FIXME I'm note sure about this construction...
|
|
||||||
void construct(T* ptr, const T& refObj) { ::new(ptr) T(refObj); }
|
|
||||||
void destroy(T* ptr) { ptr->~T(); }
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // EIGEN_MEMORY_H
|
#endif // EIGEN_MEMORY_H
|
||||||
|
@ -137,20 +137,5 @@ void test_dynalloc()
|
|||||||
delete[] foo0;
|
delete[] foo0;
|
||||||
delete[] fooA;
|
delete[] fooA;
|
||||||
}
|
}
|
||||||
|
|
||||||
// std::vector
|
|
||||||
for (int i=0; i<g_repeat*100; ++i)
|
|
||||||
{
|
|
||||||
std::vector<Vector4f, ei_new_allocator<Vector4f> > vecs(N);
|
|
||||||
for (int j=0; j<N; ++j)
|
|
||||||
{
|
|
||||||
VERIFY(size_t(vecs[j].data())%16==0);
|
|
||||||
}
|
|
||||||
std::vector<MyStruct,ei_new_allocator<MyStruct> > foos(N);
|
|
||||||
for (int j=0; j<N; ++j)
|
|
||||||
{
|
|
||||||
VERIFY(size_t(foos[j].avec.data())%16==0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user