mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
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"...
This commit is contained in:
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user