aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Benoit Jacob <jacob.benoit.1@gmail.com>2009-01-05 16:46:19 +0000
committerGravatar Benoit Jacob <jacob.benoit.1@gmail.com>2009-01-05 16:46:19 +0000
commit1b8804288050f92dd6da3ff98c9ecece5953d717 (patch)
treefbafc2762ea989009baceaefacc034382a890a4f
parent7db3f2f72a3902994fa766d8d7241d0437867739 (diff)
the empty base class optimization is not standard. Most compilers implement a basic form of it; however MSVC won't implement it if there is more than one empty base class.
For that reason, we shouldn't give Matrix two empty base classes, since sizeof(Matrix) must be optimal. So we overload operator new and delete manually rather than inheriting an empty struct for doing that.
-rw-r--r--Eigen/src/Core/Matrix.h25
1 files changed, 17 insertions, 8 deletions
diff --git a/Eigen/src/Core/Matrix.h b/Eigen/src/Core/Matrix.h
index 4851036e4..260e8c0ff 100644
--- a/Eigen/src/Core/Matrix.h
+++ b/Eigen/src/Core/Matrix.h
@@ -117,17 +117,9 @@ struct ei_traits<Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> >
};
};
-template<typename T, int Rows, int Cols, int Options,
- bool NeedsToAlign = ((Options&Matrix_AutoAlign) == Matrix_AutoAlign) && Rows!=Dynamic && Cols!=Dynamic && ((sizeof(T)*Rows*Cols)%16==0)>
-struct ei_matrix_with_aligned_operator_new : WithAlignedOperatorNew {};
-
-template<typename T, int Rows, int Cols, int Options>
-struct ei_matrix_with_aligned_operator_new<T, Rows, Cols, Options, false> {};
-
template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
class Matrix
: public MatrixBase<Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> >
- , public ei_matrix_with_aligned_operator_new<_Scalar, _Rows, _Cols, _Options>
{
public:
EIGEN_GENERIC_PUBLIC_INTERFACE(Matrix)
@@ -140,6 +132,23 @@ class Matrix
protected:
ei_matrix_storage<Scalar, MaxSizeAtCompileTime, RowsAtCompileTime, ColsAtCompileTime, Options> m_storage;
+ public: // FIXME should this be public? I'd say yes but I still don't understand then why at other places we've been having private new and delete operators.
+ enum { NeedsToAlign = (Options&Matrix_AutoAlign) == Matrix_AutoAlign
+ && SizeAtCompileTime!=Dynamic && ((sizeof(Scalar)*SizeAtCompileTime)%16)==0 };
+ typedef typename ei_meta_if<NeedsToAlign, ei_byte_forcing_aligned_malloc, char>::ret ByteAlignedAsNeeded;
+ void *operator new(size_t size) throw()
+ {
+ return ei_aligned_malloc<ByteAlignedAsNeeded>(size);
+ }
+
+ void *operator new[](size_t size) throw()
+ {
+ return ei_aligned_malloc<ByteAlignedAsNeeded>(size);
+ }
+
+ void operator delete(void * ptr) { ei_aligned_free(static_cast<ByteAlignedAsNeeded *>(ptr), 0); }
+ void operator delete[](void * ptr) { ei_aligned_free(static_cast<ByteAlignedAsNeeded *>(ptr), 0); }
+
public:
EIGEN_STRONG_INLINE int rows() const { return m_storage.rows(); }