diff options
author | Benoit Jacob <jacob.benoit.1@gmail.com> | 2009-01-08 15:20:21 +0000 |
---|---|---|
committer | Benoit Jacob <jacob.benoit.1@gmail.com> | 2009-01-08 15:20:21 +0000 |
commit | 1d52bd4cad64d8d8662f40c11210b705351b43ab (patch) | |
tree | c8fe83368e8e13ba7e8ec0c4ef078f5293cfea4d /test | |
parent | e2d2a7d2226b85569a9360b9738c15498fb454ac (diff) |
the big memory changes. the most important changes are:
ei_aligned_malloc now really behaves like a malloc
(untyped, doesn't call ctor)
ei_aligned_new is the typed variant calling ctor
EIGEN_MAKE_ALIGNED_OPERATOR_NEW now takes the class name as parameter
Diffstat (limited to 'test')
-rw-r--r-- | test/dynalloc.cpp | 39 | ||||
-rw-r--r-- | test/map.cpp | 16 | ||||
-rw-r--r-- | test/nomalloc.cpp | 21 | ||||
-rw-r--r-- | test/unalignedassert.cpp | 9 |
4 files changed, 20 insertions, 65 deletions
diff --git a/test/dynalloc.cpp b/test/dynalloc.cpp index 3b0d703ae..d829008d5 100644 --- a/test/dynalloc.cpp +++ b/test/dynalloc.cpp @@ -25,38 +25,17 @@ #include "main.h" // test compilation with both a struct and a class... -struct MyStruct : WithAlignedOperatorNew +struct MyStruct { + EIGEN_MAKE_ALIGNED_OPERATOR_NEW(MyStruct) char dummychar; Vector4f avec; }; -class MyClassA : public WithAlignedOperatorNew -{ - public: - char dummychar; - Vector4f avec; -}; - -// ..as well as with some other base classes - -class MyBaseClass -{ - public: - char dummychar; - float afloat; -}; - -class MyClassB : public WithAlignedOperatorNew, public MyBaseClass -{ - public: - char dummychar; - Vector4f avec; -}; - -class MyClassC : public MyBaseClass, public WithAlignedOperatorNew +class MyClassA { public: + EIGEN_MAKE_ALIGNED_OPERATOR_NEW(MyClassA) char dummychar; Vector4f avec; }; @@ -85,8 +64,6 @@ void test_dynalloc() { MyStruct foo0; VERIFY(size_t(foo0.avec.data())%16==0); MyClassA fooA; VERIFY(size_t(fooA.avec.data())%16==0); - MyClassB fooB; VERIFY(size_t(fooB.avec.data())%16==0); - MyClassC fooC; VERIFY(size_t(fooC.avec.data())%16==0); } // dynamic allocation, single object @@ -94,12 +71,8 @@ void test_dynalloc() { MyStruct *foo0 = new MyStruct(); VERIFY(size_t(foo0->avec.data())%16==0); MyClassA *fooA = new MyClassA(); VERIFY(size_t(fooA->avec.data())%16==0); - MyClassB *fooB = new MyClassB(); VERIFY(size_t(fooB->avec.data())%16==0); - MyClassC *fooC = new MyClassC(); VERIFY(size_t(fooC->avec.data())%16==0); delete foo0; delete fooA; - delete fooB; - delete fooC; } // dynamic allocation, array @@ -108,12 +81,8 @@ void test_dynalloc() { MyStruct *foo0 = new MyStruct[N]; VERIFY(size_t(foo0->avec.data())%16==0); MyClassA *fooA = new MyClassA[N]; VERIFY(size_t(fooA->avec.data())%16==0); - MyClassB *fooB = new MyClassB[N]; VERIFY(size_t(fooB->avec.data())%16==0); - MyClassC *fooC = new MyClassC[N]; VERIFY(size_t(fooC->avec.data())%16==0); delete[] foo0; delete[] fooA; - delete[] fooB; - delete[] fooC; } // std::vector diff --git a/test/map.cpp b/test/map.cpp index 83953b698..5159dffa1 100644 --- a/test/map.cpp +++ b/test/map.cpp @@ -31,8 +31,8 @@ template<typename VectorType> void map_class(const VectorType& m) int size = m.size(); // test Map.h - Scalar* array1 = ei_aligned_malloc<Scalar>(size); - Scalar* array2 = ei_aligned_malloc<Scalar>(size); + Scalar* array1 = ei_aligned_new<Scalar>(size); + Scalar* array2 = ei_aligned_new<Scalar>(size); Scalar* array3 = new Scalar[size+1]; Scalar* array3unaligned = size_t(array3)%16 == 0 ? array3+1 : array3; @@ -45,8 +45,8 @@ template<typename VectorType> void map_class(const VectorType& m) VERIFY_IS_APPROX(ma1, ma2); VERIFY_IS_APPROX(ma1, ma3); - ei_aligned_free(array1, size); - ei_aligned_free(array2, size); + ei_aligned_delete(array1, size); + ei_aligned_delete(array2, size); delete[] array3; } @@ -57,8 +57,8 @@ template<typename VectorType> void map_static_methods(const VectorType& m) int size = m.size(); // test Map.h - Scalar* array1 = ei_aligned_malloc<Scalar>(size); - Scalar* array2 = ei_aligned_malloc<Scalar>(size); + Scalar* array1 = ei_aligned_new<Scalar>(size); + Scalar* array2 = ei_aligned_new<Scalar>(size); Scalar* array3 = new Scalar[size+1]; Scalar* array3unaligned = size_t(array3)%16 == 0 ? array3+1 : array3; @@ -71,8 +71,8 @@ template<typename VectorType> void map_static_methods(const VectorType& m) VERIFY_IS_APPROX(ma1, ma2); VERIFY_IS_APPROX(ma1, ma3); - ei_aligned_free(array1, size); - ei_aligned_free(array2, size); + ei_aligned_delete(array1, size); + ei_aligned_delete(array2, size); delete[] array3; } diff --git a/test/nomalloc.cpp b/test/nomalloc.cpp index be4c35c48..82119e9b3 100644 --- a/test/nomalloc.cpp +++ b/test/nomalloc.cpp @@ -25,28 +25,13 @@ // this hack is needed to make this file compiles with -pedantic (gcc) #define throw(X) -// discard vectorization since the global operator new is not called in that case -#define EIGEN_DONT_VECTORIZE 1 -// discard stack allocation as that too bypasses the global operator new +// discard stack allocation as that too bypasses malloc #define EIGEN_STACK_ALLOCATION_LIMIT 0 +// any heap allocation will raise an assert +#define EIGEN_NO_MALLOC #include "main.h" -void* operator new[] (size_t n) -{ - ei_assert(false && "operator new should never be called with fixed size path"); - // the following is in case assertion are disabled - std::cerr << "operator new should never be called with fixed size path" << std::endl; - exit(2); - void* p = malloc(n); - return p; -} - -void operator delete[](void* p) throw() -{ - free(p); -} - template<typename MatrixType> void nomalloc(const MatrixType& m) { /* this test check no dynamic memory allocation are issued with fixed-size matrices diff --git a/test/unalignedassert.cpp b/test/unalignedassert.cpp index 7b6e3535d..8e0486e92 100644 --- a/test/unalignedassert.cpp +++ b/test/unalignedassert.cpp @@ -55,15 +55,16 @@ struct Bad6 Matrix<double, 3, 4> m; // bad: same reason }; -struct Good7 : Eigen::WithAlignedOperatorNew +struct Good7 { + EIGEN_MAKE_ALIGNED_OPERATOR_NEW(Good7) Vector2d m; float f; // make the struct have sizeof%16!=0 to make it a little more tricky when we allow an array of 2 such objects }; struct Good8 { - EIGEN_MAKE_ALIGNED_OPERATOR_NEW + EIGEN_MAKE_ALIGNED_OPERATOR_NEW(Good8) float f; // try the f at first -- the EIGEN_ALIGN_128 attribute of m should make that still work Matrix4f m; }; @@ -76,7 +77,7 @@ struct Good9 template<bool Align> struct Depends { - EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF(Align) + EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF(Depends,Align) Vector2d m; float f; }; @@ -97,7 +98,7 @@ void check_unalignedassert_bad() float buf[sizeof(T)+16]; float *unaligned = buf; while((reinterpret_cast<size_t>(unaligned)&0xf)==0) ++unaligned; // make sure unaligned is really unaligned - T *x = new(static_cast<void*>(unaligned)) T; + T *x = ::new(static_cast<void*>(unaligned)) T; x->~T(); } |