在glibc或C的任何标准Linux库中是否有动态数组实现?我希望能够添加到列表而不必担心它的大小.我知道std :: vector存在于C++中,但我需要C等价物.
我猜你在想realloc.但最好将结构中的列表包装起来以跟踪其当前长度
示例API
struct s_dynamic_array { int allocated; /* keep track of allocated size */ int usedLength; /* keep track of usage */ int *array; /* dynamicaly grown with realloc */ }; typedef struct s_dynamic_array s_dynamic_array; s_dynamic_array *new_dynamic_array(int initalSize); void free_dynamic_array(s_dynamic_array *array); int size_of_dynamic_array(s_dynamic_array *array); s_dynamic_array *add_int_to_dynamic_array(s_dynamic_array *array, int value); int int_at_index(s_dynamic_array *array, int index);