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

Nicolas George george at nsup.org
Tue Aug 11 01:34:18 EEST 2020


James Almer (12020-08-10):
> 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 exactly what the code does, except without the undefined
behaviors, because what you just wrote is completely invalid.

> And i *really* want to emphasize just how cold this function is,
> especially ever since av_bsf_flush() was introduced, and even more so if
> av_bsf_close() is also committed.

You missed the part where Andreas said this was a proof of concept, and
the same should be done for all similar cases. IIRC, you like
consistency.

> Skipping a 12 byte allocation does nothing on any system with a C
> library worth its salt, where it will be cached and ready to be returned
> by malloc.

It does save some memory.

> Can we not get overtly clever with code obfuscation?

There is no obfuscation, just a very standard an common practice.

Regards,

-- 
  Nicolas George
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20200811/be1fba35/attachment.sig>


More information about the ffmpeg-devel mailing list