From 1b8804288050f92dd6da3ff98c9ecece5953d717 Mon Sep 17 00:00:00 2001 From: Benoit Jacob Date: Mon, 5 Jan 2009 16:46:19 +0000 Subject: [PATCH] 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. --- Eigen/src/Core/Matrix.h | 25 +++++++++++++++++-------- 1 file 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 > }; }; -template -struct ei_matrix_with_aligned_operator_new : WithAlignedOperatorNew {}; - -template -struct ei_matrix_with_aligned_operator_new {}; - template class Matrix : public MatrixBase > - , 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 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::ret ByteAlignedAsNeeded; + void *operator new(size_t size) throw() + { + return ei_aligned_malloc(size); + } + + void *operator new[](size_t size) throw() + { + return ei_aligned_malloc(size); + } + + void operator delete(void * ptr) { ei_aligned_free(static_cast(ptr), 0); } + void operator delete[](void * ptr) { ei_aligned_free(static_cast(ptr), 0); } + public: EIGEN_STRONG_INLINE int rows() const { return m_storage.rows(); }