eteran / c-vector

A dynamic array implementation in C similar to the one found in standard C++

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Feature suggestion: clear / erase_all

DDexxeDD opened this issue · comments

commented

If I want to clear a vector, but I'm not done using it, I'm doing

cvector_free(vector);
vector = NULL;
...

Would be nice to just have cvector_clear / cvector_erase_all

I guess this could also be related to #38 as I want to 'shrink' the vector to 0

Sure, a clear function would be good. I can say that it may make sense to not reduce capacity as we often want to reduce calls to malloc/realloc.

Like if you create a vector of 20 ints and then clear it, you should be able to store 10 next time without needing to allocate.

I'd say that this is why a shrink_to_fit function is also good to have as it is complementary to clear

commented

I was being lazy using cvector_free, not reducing capacity makes much more sense