Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "main.h"
00026
00027 struct TestNew1
00028 {
00029 MatrixXd m;
00030 TestNew1() : m(20,20) {}
00031 };
00032
00033 struct TestNew2
00034 {
00035 Matrix3d m;
00036
00037 };
00038
00039 struct TestNew3
00040 {
00041 Vector2f m;
00042 };
00043
00044 struct TestNew4
00045 {
00046 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
00047 Vector2d m;
00048 float f;
00049 };
00050
00051 struct TestNew5
00052 {
00053 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
00054 float f;
00055 Matrix4f m;
00056 };
00057
00058 struct TestNew6
00059 {
00060 Matrix<float,2,2,DontAlign> m;
00061 float f;
00062 };
00063
00064 template<bool Align> struct Depends
00065 {
00066 EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF(Align)
00067 Vector2d m;
00068 float f;
00069 };
00070
00071 template<typename T>
00072 void check_unalignedassert_good()
00073 {
00074 T *x, *y;
00075 x = new T;
00076 delete x;
00077 y = new T[2];
00078 delete[] y;
00079 }
00080
00081 #if EIGEN_ALIGN_STATICALLY
00082 template<typename T>
00083 void construct_at_boundary(int boundary)
00084 {
00085 char buf[sizeof(T)+256];
00086 size_t _buf = reinterpret_cast<size_t>(buf);
00087 _buf += (16 - (_buf % 16));
00088 _buf += boundary;
00089 T *x = ::new(reinterpret_cast<void*>(_buf)) T;
00090 x[0].setZero();
00091 x->~T();
00092 }
00093 #endif
00094
00095 void unalignedassert()
00096 {
00097 #if EIGEN_ALIGN_STATICALLY
00098 construct_at_boundary<Vector2f>(4);
00099 construct_at_boundary<Vector3f>(4);
00100 construct_at_boundary<Vector4f>(16);
00101 construct_at_boundary<Matrix2f>(16);
00102 construct_at_boundary<Matrix3f>(4);
00103 construct_at_boundary<Matrix4f>(16);
00104
00105 construct_at_boundary<Vector2d>(16);
00106 construct_at_boundary<Vector3d>(4);
00107 construct_at_boundary<Vector4d>(16);
00108 construct_at_boundary<Matrix2d>(16);
00109 construct_at_boundary<Matrix3d>(4);
00110 construct_at_boundary<Matrix4d>(16);
00111
00112 construct_at_boundary<Vector2cf>(16);
00113 construct_at_boundary<Vector3cf>(4);
00114 construct_at_boundary<Vector2cd>(16);
00115 construct_at_boundary<Vector3cd>(16);
00116 #endif
00117
00118 check_unalignedassert_good<TestNew1>();
00119 check_unalignedassert_good<TestNew2>();
00120 check_unalignedassert_good<TestNew3>();
00121
00122 check_unalignedassert_good<TestNew4>();
00123 check_unalignedassert_good<TestNew5>();
00124 check_unalignedassert_good<TestNew6>();
00125 check_unalignedassert_good<Depends<true> >();
00126
00127 #if EIGEN_ALIGN_STATICALLY
00128 VERIFY_RAISES_ASSERT(construct_at_boundary<Vector4f>(8));
00129 VERIFY_RAISES_ASSERT(construct_at_boundary<Matrix4f>(8));
00130 VERIFY_RAISES_ASSERT(construct_at_boundary<Vector2d>(8));
00131 VERIFY_RAISES_ASSERT(construct_at_boundary<Vector4d>(8));
00132 VERIFY_RAISES_ASSERT(construct_at_boundary<Matrix2d>(8));
00133 VERIFY_RAISES_ASSERT(construct_at_boundary<Matrix4d>(8));
00134 VERIFY_RAISES_ASSERT(construct_at_boundary<Vector2cf>(8));
00135 VERIFY_RAISES_ASSERT(construct_at_boundary<Vector2cd>(8));
00136 #endif
00137 }
00138
00139 void test_unalignedassert()
00140 {
00141 CALL_SUBTEST(unalignedassert());
00142 }