Re: [eigen] portable reallocation...

[ Thread Index | Date Index | More Archives ]

On Fri, Feb 26, 2010 at 12:48 PM, Benoit Jacob <jacob.benoit.1@xxxxxxxxx> wrote:
> Since this will only be used by Eigen, specifically by
> conservativeResize, your portable realloc wrapper doesn't have to have
> the standard realloc API where only the new size is passed. You can
> instead write your own realloc-like function that also takes the old
> size as an argument.

Yes, I tried that. After implementing this, I stumbled over something
rather strange which we might want to discuss. :)

When creating new memory we do

template<typename T, bool Align> inline T*
ei_conditional_aligned_new(size_t size)
  T *result = reinterpret_cast<T*>(ei_conditional_aligned_malloc<Align>(sizeof(T)*size));
  return ei_construct_elements_of_array(result, size);

For integral types the compiler seems to be able to remove
'ei_construct_elements_of_array' but as soon as we try to allocate
e.g. std::complex arrays or user types T, the memory will be filled
with 'size' times 'new T()' -- why? Why do we initialize memory for
non integral types? I thought we agreed upon uninitialized matrix

Just try

VectorXcd m(50);
std::cout << m << std::endl;

it will be all zeros - and not uninitialized objects.

Maybe somebody has an idea?

- Hauke

Mail converted by MHonArc 2.6.19+