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

Måns Rullgård mru
Wed Dec 6 22:21:39 CET 2006


Michael Niedermayer <michaelni at gmx.at> writes:

> Hi
>
> On Wed, Dec 06, 2006 at 08:52:32PM +0000, M?ns Rullg?rd wrote:
>> Michael Niedermayer <michaelni at gmx.at> writes:
>> 
>> > 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
>> 
>> GCC fusses about cast from pointer to integer of different size.  In
>> this case it really doesn't matter, since we are only interested in
>> the lower 4 bits.  Using intptr_t instead would probably make the
>> warning go away.
>
> IIRC intptr_t is optional in the c standard so this is not a good idea

Yes, it's optional in the C99 standard.  The XSI extensions (which
most Unix systems more or less support) require it.  The presence of
intptr_t is indicated by INTPTR_MAX being defined.  The standard does
not allow the typedef without the #define.

-- 
M?ns Rullg?rd
mru at inprovide.com




More information about the ffmpeg-devel mailing list