From 361225068d7a3be64d9a5e767b94f92dd2f300f6 Mon Sep 17 00:00:00 2001 From: Benoit Jacob Date: Wed, 24 Dec 2008 13:59:24 +0000 Subject: [PATCH] fix bug discovered by Frank: ei_alloc_stack must really return aligned pointers --- Eigen/src/Core/util/Memory.h | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/Eigen/src/Core/util/Memory.h b/Eigen/src/Core/util/Memory.h index d7c2a00924..6e9f9987c6 100644 --- a/Eigen/src/Core/util/Memory.h +++ b/Eigen/src/Core/util/Memory.h @@ -139,8 +139,9 @@ inline static int ei_alignmentOffset(const Scalar* ptr, int maxOffset) } /** \internal - * ei_alloc_stack(TYPE,SIZE) allocates sizeof(TYPE)*SIZE bytes on the stack if sizeof(TYPE)*SIZE is - * smaller than EIGEN_STACK_ALLOCATION_LIMIT. Otherwise the memory is allocated using the operator new. + * ei_alloc_stack(TYPE,SIZE) allocates an aligned buffer of sizeof(TYPE)*SIZE bytes + * on the stack if sizeof(TYPE)*SIZE is smaller than EIGEN_STACK_ALLOCATION_LIMIT. + * Otherwise the memory is allocated on the heap. * Data allocated with ei_alloc_stack \b must be freed by calling ei_free_stack(PTR,TYPE,SIZE). * \code * float * data = ei_alloc_stack(float,array.size()); @@ -149,12 +150,13 @@ inline static int ei_alignmentOffset(const Scalar* ptr, int maxOffset) * \endcode */ #ifdef __linux__ - #define ei_alloc_stack(TYPE,SIZE) ((sizeof(TYPE)*(SIZE)>EIGEN_STACK_ALLOCATION_LIMIT) ? \ - new TYPE[SIZE] : (TYPE*)alloca(sizeof(TYPE)*(SIZE))) - #define ei_free_stack(PTR,TYPE,SIZE) if (sizeof(TYPE)*SIZE>EIGEN_STACK_ALLOCATION_LIMIT) delete[] PTR + #define ei_alloc_stack(TYPE,SIZE) ((sizeof(TYPE)*(SIZE)>EIGEN_STACK_ALLOCATION_LIMIT) \ + ? ei_aligned_malloc(SIZE) \ + : (TYPE*)alloca(sizeof(TYPE)*(SIZE))) + #define ei_free_stack(PTR,TYPE,SIZE) if (sizeof(TYPE)*SIZE>EIGEN_STACK_ALLOCATION_LIMIT) ei_aligned_free(PTR) #else - #define ei_alloc_stack(TYPE,SIZE) new TYPE[SIZE] - #define ei_free_stack(PTR,TYPE,SIZE) delete[] PTR + #define ei_alloc_stack(TYPE,SIZE) ei_aligned_malloc(SIZE) + #define ei_free_stack(PTR,TYPE,SIZE) ei_aligned_free(PTR) #endif /** \class WithAlignedOperatorNew