Re: [eigen] Question regarding QtAllignedMalloc / qRealloc |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [eigen] Question regarding QtAllignedMalloc / qRealloc
- From: Benoit Jacob <jacob.benoit.1@xxxxxxxxx>
- Date: Sun, 6 Nov 2011 10:21:08 -0500
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=zlfDiSOGed4qEBPB6ckL4rPzFs1kCfPvCXxbll9aSbo=; b=lRALaN1jT2jRQ0dB7V2qlAS63U53XvfC4aPcuHi1bOlY5LbN7JcO1vStcWpepCAbsL h9S6FgqO3vIB4tSUU6TzuzaWxHIFy0HFC8QDha5Vu1UyS0ywHnJgn6Y0Ih7mycn5tJzD OwIzZnJHoVBCSYZZVpmrwOuNCLC5Ogjlo9qNg=
Sorry for the late reply.
You're right, this function is completely buggy. I think that any
correct implementation has to call the preexisting qRealloc function,
see e.g. how our own handmade_aligned_realloc works.
Benoit
2011/10/7 Schmidt, Michael <Michael.Schmidt@xxxxxxxxxxxxxxxxxxx>:
> Dear all,
> I just stumbled over the QtAlignedMalloc file and the qRealloc method
> provided therein. The function is implemented this way:
>
> void *qRealloc(void *ptr, size_t size)
> {
> void* newPtr = Eigen::internal::aligned_malloc(size);
> memcpy(newPtr, ptr, size);
> Eigen::internal::aligned_free(ptr);
> return newPtr;
> }
>
> My question is: Why can you do the memcpy in that way? If size is larger
> than the the block pointed to by ptr, memcpy will possibly access invalid
> memory locations, won't it?
>
> Best regards, Michael