Feature suggestion: clear / erase_all
DDexxeDD opened this issue · comments
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 int
s 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
I was being lazy using cvector_free
, not reducing capacity makes much more sense