From f52d119b9c4f9b6dfbb91183de08143fdf3cc94c Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Wed, 3 Sep 2008 00:32:56 +0000 Subject: Solve a big issue with data alignment and dynamic allocation: * add a WithAlignedOperatorNew class with overloaded operator new * make Matrix (and Quaternion, Transform, Hyperplane, etc.) use it if needed such that "*(new Vector4) = xpr" does not failed anymore. * Please: make sure your classes having fixed size Eigen's vector or matrice attributes inherit WithAlignedOperatorNew * add a ei_new_allocator STL memory allocator to use with STL containers. This allocator really calls operator new on your types (unlike GCC's new_allocator). Example: std::vector data(10); will segfault if the vectorization is enabled, instead use: std::vector > data(10); NOTE: you only have to worry if you deal with fixed-size matrix types with "sizeof(matrix_type)%16==0"... --- test/nomalloc.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'test/nomalloc.cpp') diff --git a/test/nomalloc.cpp b/test/nomalloc.cpp index a1b12f57c..78bb12a8a 100644 --- a/test/nomalloc.cpp +++ b/test/nomalloc.cpp @@ -1,6 +1,7 @@ // This file is part of Eigen, a lightweight C++ template library // for linear algebra. Eigen itself is part of the KDE project. // +// Copyright (C) 2008 Gael Guennebaud // Copyright (C) 2006-2008 Benoit Jacob // // Eigen is free software; you can redistribute it and/or @@ -29,14 +30,14 @@ #include "main.h" void* operator new[] (size_t n) - { - ei_assert(false && "operator new should never be called with fixed size path"); - // the following is in case assertion are disabled - std::cerr << "operator new should never be called with fixed size path" << std::endl; - exit(2); - void* p = malloc(n); - return p; - } +{ + ei_assert(false && "operator new should never be called with fixed size path"); + // the following is in case assertion are disabled + std::cerr << "operator new should never be called with fixed size path" << std::endl; + exit(2); + void* p = malloc(n); + return p; +} void operator delete[](void* p) throw() { @@ -54,8 +55,6 @@ template void nomalloc(const MatrixType& m) int rows = m.rows(); int cols = m.cols(); - // this test relies a lot on Random.h, and there's not much more that we can do - // to test it, hence I consider that we will have tested Random.h MatrixType m1 = MatrixType::Random(rows, cols), m2 = MatrixType::Random(rows, cols), m3(rows, cols), -- cgit v1.2.3