This forum has been archived. All content is frozen. Please use KDE Discuss instead.

[SOLVED] Unaligned Array Assertion in Valgrind

Tags: None
(comma "," separated)
dubmarauder
Registered Member
Posts
14
Karma
0
OS
Hello All,

I am running the latest stable Eigen release (from the eigen-2.0.0.tar.bz2 tarball) under Ubuntu 8.10 and compiling with gcc version 4.3.2 (Ubuntu 4.3.2-1ubuntu12).

In the process of locating a memory leak in a program I am working with, I ran the program under valgrind and triggered the following assertion:


Code: Select all
test: ../Eigen/Eigen/src/Core/MatrixStorage.h:44: Eigen::ei_matrix_array::ei_matrix_array() [with T = float, int Size = 4, int MatrixOptions = 2, bool Align = true]: Assertion `(reinterpret_cast(array) & 0xf) == 0 && "this assertion is explained here: http://eigen.tuxfamily.org/dox/UnalignedArrayAssert.html  **** READ THIS WEB PAGE !!! ****"' failed.



I read over the suggestions at http://eigen.tuxfamily.org/dox/Unaligne ... ssert.html and the thread at -solved-unaligned- ... 30974.html, but have been unable to resolve the issue. Here is the simplest reproduction of the problem I could come up with:

Code: Select all
#include
#include
#include

using namespace std;
USING_PART_OF_NAMESPACE_EIGEN

class TestObject
{
public:
   EIGEN_MAKE_ALIGNED_OPERATOR_NEW   

   void member_function()
   {
      vector > local_vector;
      local_vector.resize(3);
   }

   Matrix member_matrix;
};


int main( int argc, char** argv )
{
   vector g_rods;

   TestObject test_object;
   test_object.member_function();

   g_rods.push_back( test_object );

   cout << "Hello, world!" << endl;
   return 1;
}


When I compile (g++ -IEigen/ test.cpp -o test) and run (valgrind ./test) the above code, I trigger the unaligned array assertion.

Playing around with the above code, I can eliminate the assertion by doing any of the following:
1) Changing the Matrix in member_function() and member_matrix to the same dimensions
2) Not calling test_object.member_function() before pushing test_object
3) Eliminating the local_vector.resize call
4) Eliminating the member_matrix matrix

Am I using the library wrong, are there any obvious mistakes in the above code, or am I simply not going to be able to use valgrind in this situation (the assertion is not tripped when I run the program outside of valgrind)?

Thank you for your advice. To the developers of Eigen, great job! Working with the Eigen has been a pleasure!
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
using a custom class with Eigen objects as attributes within std::vector does not work with last stable version. This has been fixed in trunk. I did not backported it into the stable branch yet because it is a relatively big change, and it has not been much tested. So could you try with svn trunk ?
dubmarauder
Registered Member
Posts
14
Karma
0
OS
I just compiled the code I posted with the svn trunk, and the program ran under valgrind without issue. Thank you for the assistance!


Bookmarks



Who is online

Registered users: Bing [Bot], Evergrowing, Google [Bot], rblackwell