[Ffmpeg-devel] [RFC] another attempt at memalign realloc
Thu Dec 7 21:42:33 CET 2006
On Thu, 7 Dec 2006, MXns_RullgXrd wrote:
> "Herv? W." <H.O.W.aka.V+ffmpeg at gmail.com> writes:
> > 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
> Never worked with embedded systems, have you?
> M?ns Rullg?rd
> mru at inprovide.com
Having spent many years working in embedded systems I can say that it is
not necessarily uncommon to run out of memory. Though in my case it was
because Wind River had a very bad malloc implementation up through at
least version 5.4 that fragmented horribly when realloc was used
(replacing it with dlmalloc made a *huge* difference in both performance
and stability - bootup went from 50 minutes to 3). Also, I recall having
to do my own memory alignment then becuase the VxWorks memalign was
broken. Of course the dlmalloc version worked perfectly.
If possible, the best thing to do is to allocate the buffers once, or have
a pool of buffers with the appropriate alignment. Frequent calls to
malloc/realloc and free can lead to memory fragmentation and poor
performance on some platforms.
More information about the ffmpeg-devel