[Ffmpeg-devel] [RFC] another attempt at memalign realloc

Hervé W. H.O.W.aka.V+ffmpeg
Thu Dec 7 20:46:41 CET 2006


Hi,

On 07/12/06, Reimar D?ffinger <Reimar.Doeffinger at stud.uni-karlsruhe.de> wrote:
> Hello,
> On Thu, Dec 07, 2006 at 08:50:14PM +0200, Oded Shimon wrote:
> > On Thu, Dec 07, 2006 at 07:05:55PM +0100, Reimar D?ffinger wrote:
> > > Actually, there is a rather obvious solution.
> > > Disadvantage: av_realloc without MEMALIGN_HACK now _always_ has the time
> > > and space costs of av_malloc.
> > ...
> > > -    return realloc(ptr, size);
> > > +    p2 = av_malloc(size);
> > > +    if (!p2) return NULL;
> > > +    ptr = realloc(ptr, size);
> > > +    if(!((long)ptr&15))
> > > +        return ptr;

[...]

> > I assume you meant to put the av_malloc line AFTER this line... ?
>
> Certainly not! Then we would have no way back if the malloc fails, which
> conflicts with how realloc is supposed to behave, that's exactly the
> point.

When would malloc fail? no large enough block of available memory,...
any more conditions? no? That should be pretty rare. Does any of
ffmpegs code even use  the data after av_realloc returns NULL ?

And since you would like to have correct realloc behaviour...

In your MEMALIGN_HACK path:
> +    p2 = realloc(p - diff, size + 16);
> +    p2 += diff;
> +    if(!((long)p2&15))
> +        return p2;

If realloc returns NULL, you add diff to NULL...

Good luck.
-V




More information about the ffmpeg-devel mailing list