Mastodon Feed: Post

Mastodon Feed

NfNitLoop ("Cody Casterline 🏳️‍🌈") wrote:

@jsonstein It's safe, though, because the lifetimes of all references to that memory are tracked. While the drain iterator exists, nothing else is allowed to use that memory. Once it no longer exists, the allocated memory is free to be re-used by the HashMap implementation.

That's a lot more efficient than constantly freeing and re-allocating the memory. Zero-cost by default! ❤️

Strings do this when you use them as input buffers too. Only grow when they read a line/chunk that's larger.