[Ffmpeg-devel] [RFC] another attempt at memalign realloc
Reimar Döffinger
Reimar.Doeffinger
Wed Dec 6 17:34:12 CET 2006
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
-------------- next part --------------
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))
+ return ptr2;
+ ptr = ptr2 - diff;
+ diff= ((-(long)ptr - 1)&15) + 1;
+ ptr += diff;
+ memove(ptr, ptr2, size);
+ ((char*)ptr)[-1]= diff;
+ return ptr;
#else
return realloc(ptr, size);
#endif
More information about the ffmpeg-devel
mailing list