Quoting Nicolas George (2020-07-01 17:13:22) > Anton Khirnov (12020-07-01): > > Why a template? It seems simpler to add a struct like > > typedef struct AVRefcount { > > atomic_uint refcount; > > void *opaque; > > void (*free)(void *opaque); > > } AVRefcount; > > and then embed it in everything that wants to be refcounted. All just > > normal structs and functions, no layers of macros. > > Because what you propose requires an extra layer of pointers, which is > both annoying when reading and writing the code
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. > and inefficient when running it. Why? I do not see how an extra pointer dereference could possibly matter here. > > Also because what you propose has void pointers, and therefore will not > benefit from the compiler checking the types at compilation time. In my experience, providing the wrong opaque pointer has never been a common source of bugs (and is typically easily noticeable if it does happen), so I see that as an acceptable tradeoff. -- Anton Khirnov _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".