Memory allocation question


#1

I created a vector and I filled with N million element. If I add new element, and I reach the capacity of vector, it will automatic reallocate vector capacity with double size. It’s very efficient.

But I tuncate this vector near zero (or zero). Can I shrink the allocated memory?


#2

Yes with https://doc.rust-lang.org/std/vec/struct.Vec.html#method.shrink_to_fit It will deallocate or realloc