[FFmpeg-devel] [PATCH] Doxygenate libavutil/mem.h

Michael Niedermayer michaelni
Mon Sep 24 04:49:05 CEST 2007


On Sun, Sep 23, 2007 at 10:11:37PM -0400, Rich Felker wrote:
> > > - * av_realloc semantics (same as glibc): if ptr is NULL and size > 0,
> > > - * identical to malloc(size). If size is zero, it is identical to
> > > - * free(ptr) and NULL is returned.
> > > + * Allocates or reallocates a block of size \p size with alignment
> > > + * suitable for all memory accesses (including vectors if available on
> > > + * the CPU).
> > 
> > this is not true, the alignment will be as bad as what realloc() returns
> > currently, we could fix the implementaton (IIRC there where some patches)
> > but it would slow down av_realloc() considerably (>2x) if the realloc()
> > output isnt aligned
> :(

to elaborate on the problem a little ...

we cant malloc(size); memcpy(); free() as we dont know the allocated size
we would have to realloc() first but thats 2x speedloss or we would have to
somehow store the allocated size for every av_malloc() and av_realloc()
but that really is ugly and wastes memory also malloc();memcpy();free()
might still be slower than a realloc()

for the memalign hack case we could realloc() and memmove() but that as
well is likely 2x slower

so speedwise and complexity wise it seems best to just accept that
av_realloc() doesnt gurantee alignment for SIMD and thus use av_malloc()
whereever the data might be touched by SIMD code (IIRC there are very few
cases where thats the case, most stuff for SIMD never needs reallocating)

Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

it is not once nor twice but times without number that the same ideas make
their appearance in the world. -- Aristotle
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20070924/c6e349d2/attachment.pgp>

More information about the ffmpeg-devel mailing list