Vec is asymmetric with memory handling

I think Vec is at least missing some sort of generic shrink()/garbage_collect()/... function with good asymptotics, so that if you called it after every potentially-len-shrinking operation it wouldn’t make your program accidentally-quadratic the way that overuse of shrink_to_fit can.

If it isn't the default, it should at least be easy to manually use Vec as a dynamic array with (only) a constant factor memory overhead, if you want to.

Given that (as far as I remember the docs) Vec's exact growth strategy isn't guaranteed/fixed, I'm not even sure if it is currently possible at all to do this manually in a future-proof way, and in any case it's not super trivial to implement.

6 Likes