[Libav-user] av_malloc_array fragmentation on Linux

gga ggarra13 at gmail.com
Tue Aug 11 02:09:07 EEST 2020


On 10/8/20 18:55, gga wrote:
> I modified my code to rely on ffmpeg's av_malloc's functions and I am 
> now seeing what appears to be memory fragmentation on the Linux platform.
>
> My code is C++ using operator new[], like the following:
>
>   struct aligned16_uint8_t
>   {
>     uint8_t x;
>
>     inline void* operator new(size_t size)
>     {
>         void* ptr = av_malloc( size );
>         if (!ptr) throw std::bad_alloc();
>         return ptr;
>     }
>
>     inline void operator delete( void* ptr )
>     {
>         av_free( ptr );
>     }
>
>     inline void* operator new[](size_t size)
>     {
>         void* ptr = av_malloc_array( size, sizeof(aligned16_uint8_t) );
>         if (!ptr) throw std::bad_alloc();
>         return ptr;
>     }
>
>     inline void operator delete[]( void* ptr )
>     {
>         av_free( ptr );
>     }
>   };
>
> The above works fine on Windows and Mac, but on Linux it seems like it 
> leaks memory / fragments it.  Looking at the av_malloc implementation 
> for Linux, I saw it relies on posix_memalign, but nothing else seems 
> differently.
>
Oh, yes.  I should mention that the memory fragmentation happens after I 
run the allocation of a sequence of frames multiple times and with some 
frames being swapped out of memory at the same time, and with all frames 
being of the same size.

-- 
Gonzalo Garramuño



More information about the Libav-user mailing list