[FFmpeg-devel] [PATCH] avcodec/bsf: Avoid allocation for AVBSFInternal

Andreas Rheinhardt andreas.rheinhardt at gmail.com
Tue Aug 11 02:17:17 EEST 2020


Andreas Rheinhardt:
> James Almer:
>> On 8/10/2020 7:11 PM, Nicolas George wrote:
>>> James Almer (12020-08-10):
>>>> Personally, i don't like it. It's extra complexity to save a single 8 or
>>>> 12 byte allocation that happens once during bsf alloc. It's kind of a
>>>> pointless micro-optimization.
>>>
>>> I do not agree at all.
>>>
>>> First, it is not extra complexity, it actually makes the code simpler:
>>> less mutually dependant allocations that can lead to leaks if they are
>>> not handled properly, better guarantees, for no more code.
>>
>> It adds an extra struct and makes the code harder to read. Might as well
>> just do
>>
>> ctx = av_mallocz(sizeof(*ctx) + sizeof(AVBSFInternal));
>> ctx->internal = &ctx[1];
> 
> This is not ok due to padding/alignment.
> 
Forgot to mention that you are also circumventing the type system
whereas my version doesn't.

- Andreas


More information about the ffmpeg-devel mailing list