rust-lang / wg-allocators

Home of the Allocators working group: Paving a path for a standard set of allocator traits to be used in collections!
http://bit.ly/hello-wg-allocators
203 stars 9 forks source link

Question: protocol around Allocator::grow #126

Open yanchith opened 1 month ago

yanchith commented 1 month ago

UPDATE: turns out I read the code too hastily. RawVec actually doesn't retry. The rest of the question stands, though.

Some collections support in-place growing with Allocator::grow. ~Vec (via RawVec) first attempts to grow, and if that fails, attempts to reallocate.~

~This seems reasonable to me, because the allocator may refuse to grow an allocation, if it can't do it efficiently, and RawVec tries again if growing fails.~

Should collections generally retry? If so, should we document it in the allocator trait? Arguably, it is somewhat documented by the "or if growing otherwise fails" text, but it would be nice to know that the collection should attempt to call allocate itself, if growing failed.