Re: [eigen] portable reallocation...

[ Thread Index | Date Index | More Archives ]

2010/2/26 Hauke Heibel <hauke.heibel@xxxxxxxxxxxxxx>:
> Hi guys,
> Since somebody asked on the forum I looked into implementing
> .conservativeResize(...) based on realloc where that makes sense. Such
> an implementation might yield higher performance since in some cases
> the data does not need to be copied.
> The issue I am running into right now is that there is no portable
> version of _mm_realloc. On MSVC this is not really a problem since
> _mm_malloc = _aligned_alloc and thus I can fall back to
> _aligned_realloc. On other systems on the other hand side, I have no
> idea how _mm_malloc is implemented. An alternative would be to provide
> something as shown here
> Also not very nice and still no solution since the standard does not
> define a function mm_getsize. On MSVC it is called _msize and on other
> systems it has different names - when it exists at all.
> The gist is that without knowing the size of the memory buffer I am
> about to reallocate, there is no way in implementing a malloc/free
> based version of realloc.
> Any suggestions?

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.

This is just like our ei_aligned_delete: it takes the size as an
argument in order to implement the for loop calling destructors. This
is unlike the usual "delete[]" that determines the array size by
itself, but that doesn't matter, since in all contexts where we're
calling ei_aligned_delete, we do know the size.


> - Hauke

Mail converted by MHonArc 2.6.19+