Re: [eigen] portable reallocation... |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [eigen] portable reallocation...
- From: Hauke Heibel <hauke.heibel@xxxxxxxxxxxxxx>
- Date: Fri, 26 Feb 2010 14:24:48 +0100
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type; bh=2ZMrN1sPDvN3+Hps4g1TuUFGt+D/Ev7YvCSmlxPsZu4=; b=VAxPJmheY54THw9cMJH3KvgJ01fDt4cGxq7eH5OXAYMgiVqG9tFOD8P6wkdWFAPbev EVkOYrHnJIACGP9tHa0ERUEqv8pBNDYGR7HJyUBWhzJKkU2+4euS1H23GX2Dv74dHXZi FaMsUuKsli5ZXwZlopVfq8idU4Vv4wvfGgbZc=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; b=RzBeFoKhEcyrz4J57YUrFzbdj2a4SB/GRMNeuyidGZ0aOAS/QaZ12qmathD4xoUNCV m5dpAFgKfeJvppinTrs26aV46WosZZICyBFtIJbrLA2cn41VqcHe6/6yVtv/eDBtscUf JFXqevvyWMQyUgh8c9wqQ6bDV8l61biU+G75w=
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
creation!?
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