Hacker News new | past | comments | ask | show | jobs | submit login

> Is reusing an allocation while changing its size a thing you expect to be able to do?

It's something you should expect to be able to try to do. The underlying allocator may reject the request depending on context (maybe it is works for large sizes only, for example). This is provided by Rust's Allocator trait realloc_in_place() API, which returns CannotReallocInPlace if it isn't possible.

For Vec::collect, in the event that the storage cannot be reused smaller in place, I think it would be reasonable to free it and allocate an appropriately sized buffer instead.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: