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
This commit is contained in:
Benoit Jacob
2009-01-08 15:20:21 +00:00
parent e2d2a7d222
commit 1d52bd4cad
21 changed files with 215 additions and 243 deletions

View File

@@ -101,10 +101,10 @@ with size=50, rows=50, columns=1.
Here is this constructor:
\code
inline ei_matrix_storage(int size, int rows, int) : m_data(ei_aligned_malloc<T>(size)), m_rows(rows) {}
inline ei_matrix_storage(int size, int rows, int) : m_data(ei_aligned_new<T>(size)), m_rows(rows) {}
\endcode
Here, the \a m_data member is the actual array of coefficients of the matrix. As you see, it is dynamically allocated. Rather than calling new[] or malloc(), as you can see, we have our own ei_aligned_malloc defined in src/Core/util/Memory.h. What it does is that if vectorization is enabled, then it uses a platform-specific call to allocate a 128-bit-aligned array, as that is very useful for vectorization with both SSE2 and AltiVec. If vectorization is disabled, it amounts to the standard new[].
Here, the \a m_data member is the actual array of coefficients of the matrix. As you see, it is dynamically allocated. Rather than calling new[] or malloc(), as you can see, we have our own ei_aligned_new defined in src/Core/util/Memory.h. What it does is that if vectorization is enabled, then it uses a platform-specific call to allocate a 128-bit-aligned array, as that is very useful for vectorization with both SSE2 and AltiVec. If vectorization is disabled, it amounts to the standard new[].
As you can see, the constructor also sets the \a m_rows member to \a size. Notice that there is no \a m_columns member: indeed, in this partial specialization of ei_matrix_storage, we know the number of columns at compile-time, since the _Cols template parameter is different from Dynamic. Namely, in our case, _Cols is 1, which is to say that our vector is just a matrix with 1 column. Hence, there is no need to store the number of columns as a runtime variable.

View File

@@ -10,7 +10,7 @@ namespace Eigen {
- \ref stillstillstuck
- \ref movetotop
- \ref bugineigen
- \ref nomacro
- \ref conditional
<hr>
\section what What kind of code made this assertion fail?
@@ -54,7 +54,7 @@ class Foo
Eigen::Vector2d v;
...
public:
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
EIGEN_MAKE_ALIGNED_OPERATOR_NEW(Foo)
};
...
@@ -144,7 +144,7 @@ class Foo
double x;
Eigen::Vector2d v;
public:
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
EIGEN_MAKE_ALIGNED_OPERATOR_NEW(Foo)
};
\endcode
@@ -156,7 +156,7 @@ class Foo
Eigen::Vector2d v;
double x;
public:
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
EIGEN_MAKE_ALIGNED_OPERATOR_NEW(Foo)
};
\endcode
@@ -168,25 +168,6 @@ Dynamic-size matrices and vectors, such as Eigen::VectorXd, allocate dynamically
No, it's not our bug. It's more like an inherent problem of the C++ language -- though it must be said that any other existing language probably has the same problem. The problem is that there is no way that you can specify an aligned "operator new" that would propagate to classes having you as member data.
\section nomacro I don't like macros! Any solution with inheritance?
Yes, you can let your class Foo publicly inherit Eigen::WithAlignedOperatorNew, like this:
\code
class Foo : public Eigen::WithAlignedOperatorNew
{
...
Eigen::Vector2d v;
...
};
...
Foo *foo = new Foo;
\endcode
This solution gives the same result as the macro. It has the disadvantage that if Foo already had a base class, you are now doing multiple inheritance, and this situation is sometimes handled wrongly by certain compilers -- we've been having trouble with MSVC. The solution with the macro is therefore safer.
\section conditional What if I want to do this conditionnally (depending on template parameters) ?
For this situation, we offer the macro EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF(NeedsToAlign). It will generate aligned operators like EIGEN_MAKE_ALIGNED_OPERATOR_NEW if NeedsToAlign is true. It will generate operators with the default alignment if NeedsToAlign is false.
@@ -202,7 +183,7 @@ template<int n> class Foo
Vector v;
...
public:
EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF(NeedsToAlign)
EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF(Foo,NeedsToAlign)
};
...