[FFmpeg-devel] [PATCH 1/3] lavu: add a template for refcounted objects.
Anton Khirnov
anton at khirnov.net
Wed Jul 1 21:24:34 EEST 2020
Quoting Nicolas George (2020-07-01 18:47:15)
> Anton Khirnov (12020-07-01):
> > instead of
> > #define AVRC_TYPE AVBuffer
> > #define AVRC_PREFIX prefix
> > #define AVRC_FIELD refcount
> > you'd have
> > av_refcount_init(&buf->refcount, buf, buffer_free);
> > Does not look more annoying to me, to the contrary macro templates
> > require more effort to understand or debug.
>
> The annoying part is to have to dereference buf->opaque each time we
> need to use it. It clutters all the code that use a structure. It is
> completely unacceptable to me.
You do not dereference buf->opaque. You pass it to the free callback
when the refcount reaches zero, that is the only way it should ever be
used.
>
> > Why? I do not see how an extra pointer dereference could possibly matter here.
>
> It does not matter much, but in tights loops it can.
If you constantly alloc and free objects in tight loops then you have
way bigger problems than a single pointer dereference. This is really a
red herring.
Beyond that, I suppose this is a personal preference difference. Some
more opinions from other people would be welcome.
--
Anton Khirnov
More information about the ffmpeg-devel
mailing list