+
+/************************************************************************
+ * Dynamic arrays with progressive allocation (Preferred API)
+ ************************************************************************/
+typedef struct vlc_array_t
+{
+ int i_count;
+ void ** pp_elems;
+} vlc_array_t;
+
+static inline void vlc_array_init( vlc_array_t * p_array )
+{
+ memset( p_array, 0, sizeof(vlc_array_t) );
+}
+
+static inline void vlc_array_clear( vlc_array_t * p_array )
+{
+ free( p_array->pp_elems );
+ memset( p_array, 0, sizeof(vlc_array_t) );
+}
+
+static inline vlc_array_t * vlc_array_new( void )
+{
+ vlc_array_t * ret = (vlc_array_t *)malloc( sizeof(vlc_array_t) );
+ if( ret ) vlc_array_init( ret );
+ return ret;
+}
+
+static inline void vlc_array_destroy( vlc_array_t * p_array )
+{
+ if( !p_array )
+ return;
+ vlc_array_clear( p_array );
+ free( p_array );
+}
+
+
+/* Read */
+static inline int
+vlc_array_count( vlc_array_t * p_array )
+{
+ return p_array->i_count;
+}
+
+static inline void *
+vlc_array_item_at_index( vlc_array_t * p_array, int i_index )
+{
+ return p_array->pp_elems[i_index];
+}
+
+static inline int
+vlc_array_index_of_item( vlc_array_t * p_array, void * item )
+{
+ int i;
+ for( i = 0; i < p_array->i_count; i++)
+ {
+ if( p_array->pp_elems[i] == item )
+ return i;
+ }
+ return -1;
+}
+
+/* Write */
+static inline void
+vlc_array_insert( vlc_array_t * p_array, void * p_elem, int i_index )
+{
+ TAB_INSERT_CAST( (void **), p_array->i_count, p_array->pp_elems, p_elem, i_index );
+}
+
+static inline void
+vlc_array_append( vlc_array_t * p_array, void * p_elem )
+{
+ vlc_array_insert( p_array, p_elem, p_array->i_count );
+}
+
+static inline void
+vlc_array_remove( vlc_array_t * p_array, int i_index )
+{
+ if( i_index >= 0 )
+ {
+ if( p_array->i_count > 1 )
+ {
+ memmove( p_array->pp_elems + i_index,
+ p_array->pp_elems + i_index+1,
+ ( p_array->i_count - i_index - 1 ) * sizeof( void* ) );
+ }
+ p_array->i_count--;
+ if( p_array->i_count == 0 )
+ {
+ free( p_array->pp_elems );
+ p_array->pp_elems = NULL;
+ }
+ }
+}
+
+