eteran / c-vector

A dynamic array implementation in C similar to the one found in standard C++
MIT License
737 stars 109 forks source link

Feature suggestion: Shrink arrays #38

Closed julianhartmer closed 1 year ago

julianhartmer commented 2 years ago

What do you think about automatic shrinking of c-vectors? Currently, the vector capacity doubles when capacity == size. How about cutting the vector capacity in half when the (size >> 2) < capacity? This way, the capacity is cut in half when only a fourth of the capacity is used. I could make this feature optional by enabling it when CVECTOR_SHRINK is defined. What are your thoughts?

eteran commented 2 years ago

I'm open to it, especially if controlled by a macro so it's opt in. I'd also be even more in favor of a cvector_shrink_to_fit macro of some kind that would resize the vector to be an exact fit when the user wants it so.