aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/nomalloc.cpp
diff options
context:
space:
mode:
authorGravatar Gael Guennebaud <g.gael@free.fr>2008-09-03 00:32:56 +0000
committerGravatar Gael Guennebaud <g.gael@free.fr>2008-09-03 00:32:56 +0000
commitf52d119b9c4f9b6dfbb91183de08143fdf3cc94c (patch)
tree2369642bacec55b4d372797d42d27c74c6ac75eb /test/nomalloc.cpp
parentd8df318d77b8a9bd9d6274f25145639603c2e8d4 (diff)
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<Vector4f> data(10); will segfault if the vectorization is enabled, instead use: std::vector<Vector4f,ei_new_allocator<Vector4f> > data(10); NOTE: you only have to worry if you deal with fixed-size matrix types with "sizeof(matrix_type)%16==0"...
Diffstat (limited to 'test/nomalloc.cpp')
-rw-r--r--test/nomalloc.cpp19
1 files changed, 9 insertions, 10 deletions
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 <g.gael@free.fr>
// Copyright (C) 2006-2008 Benoit Jacob <jacob@math.jussieu.fr>
//
// 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<typename MatrixType> 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),