[vlc-devel] [RFC 0/3] Improving vlc_array_t
rom1v at videolabs.io
Sun Jul 22 20:13:19 CEST 2018
Thank you for your review.
On Sun, Jul 22, 2018 at 06:16:18PM +0200, Denis Charmet wrote:
> On 2018-07-19 17:57, Romain Vimont wrote:
> > There are 3 arrays API in vlc_arrays.h:
> > 1. TAB_* macros
> > 2. ARRAY_* macros
> > 3. vlc_array_t + functions
> > When we want a dynamic array of pointers, the vlc_array_t seems more
> > appropriate. Moreover, the macro versions abort() on allocation failure.
> In my opinion, an array of void* pointers feels generic to the point of
> I completely get that handling insertion, deletion, lookup for every
> structure is a PITA but I think that arrays of void* are more nefarious than
> Vectors are awesome but as far as I know they handle more cases than the
> vlc_array_t: they allocate the size of the object, call its destructor on
> deletion and ensure type safety. To be fair, I would personally prefer if
> the array allocated the whole size of each element, like calloc does but I
> agree that it probably won't be enough since we have no way in C to enforce
> the C++ rule of 3 (constructor/destructor/copy) to make it safer.
Yes, I'd say that vlc_array_t is similar to vector<void*>.
> In that regard, I prefer the TAB_ macros for their flexibility and type
> preserving even with their drawbacks and would love to see them improved
> rather than relying on arrays of void* pointers.
OK, so I will apply the changes to TAB_* instead, then.
How do we avoid calls to abort() in these macros? Do we add another
output parameter to report allocation failures?
> In any case I agree that the playlist should be flat and ordered.
> I lack the
> algorithmic theoretical knowledge to propose a better structure than an
> array or a linked chain. But maybe if you elaborate on what the playlist
> elements will actually hold we could come up with a proposition that will
> satisfy everybody.
I don't exactly know yet. Probably pointers to structures containing an
input item and other data.
The operations are insert/append, delete, sort, shuffle...
I think I will start with an array, and we could switch to something
else if perfs are not ok for some operations. Unless someone suggests
something else which is obviously a better choice :) What do you think?
> Denis Charmet - TypX
> Le mauvais esprit est un art de vivre
More information about the vlc-devel