[Ffmpeg-devel] [RFC] another attempt at memalign realloc
Michael Niedermayer
michaelni
Wed Dec 6 21:38:51 CET 2006
Hi
On Wed, Dec 06, 2006 at 05:34:12PM +0100, Reimar D?ffinger wrote:
> Hello,
> I came up with the attached idea, but it seems so simple that I can't
> get rid of the feeling there is yet another problem with that (except
> that the performance might be really bad), otherwise somebody should
> have had that same idea during all this wild hacking around on it *g*.
> Well, please help me and have a very close look at it and say what you
> think.
>
> Greetings,
> Reimar D?ffinger
> Index: libavutil/mem.c
> ===================================================================
> --- libavutil/mem.c (revision 7217)
> +++ libavutil/mem.c (working copy)
> @@ -105,6 +105,7 @@
> {
> #ifdef CONFIG_MEMALIGN_HACK
> int diff;
> + void *ptr2;
> #endif
>
> /* let's disallow possible ambiguous cases */
> @@ -112,10 +113,17 @@
> return NULL;
>
> #ifdef CONFIG_MEMALIGN_HACK
> - //FIXME this isn't aligned correctly, though it probably isn't needed
> if(!ptr) return av_malloc(size);
> diff= ((char*)ptr)[-1];
> - return realloc(ptr - diff, size + diff) + diff;
> + ptr2 = realloc(ptr - diff, size + 16) + diff;
> + if(!((int)ptr2&15))
hmm didnt this cast cause same silly warning with gcc on x86-64 or
something, anyway long and int casts are mixed not a real issue though
> + return ptr2;
> + ptr = ptr2 - diff;
void * arithmetic
> + diff= ((-(long)ptr - 1)&15) + 1;
> + ptr += diff;
> + memove(ptr, ptr2, size);
> + ((char*)ptr)[-1]= diff;
> + return ptr;
the comment says:
If size is zero, it is identical to
* free(ptr) and NULL is returned.
this isnt true, though it neither was before your patch in the
CONFIG_MEMALIGN_HACK case ...
except these nitpicks iam fine with the patch
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
If you really think that XML is the answer, then you definitly missunderstood
the question -- Attila Kinali
More information about the ffmpeg-devel
mailing list