-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clarify Vec's documentation about buffer reuse #84488
Comments
I guess this also includes in-place iteration? |
In-place iteration is a fancy case of type-conversion. Simpler examples are conversions to |
Maybe it would be more clear to say "may be reused by another allocation"? That doesn't imply it has to be a Vec that reuses the memory. |
@rustbot label +A-collections +C-enhancement +T-libs |
@rustbot claim |
…arth Rollup of 7 pull requests Successful merges: - rust-lang#85223 (rustdoc: Clarified the attribute which prompts the warning) - rust-lang#88847 (platform-support.md: correct ARMv7+MUSL platform triple notes) - rust-lang#88963 (Coerce const FnDefs to implement const Fn traits ) - rust-lang#89376 (Fix use after drop in self-profile with llvm events) - rust-lang#89422 (Replace whitespaces in doctests' name with dashes) - rust-lang#89440 (Clarify a sentence in the documentation of Vec (rust-lang#84488)) - rust-lang#89441 (Normalize after substituting via `field.ty()`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
…arth Rollup of 7 pull requests Successful merges: - rust-lang#85223 (rustdoc: Clarified the attribute which prompts the warning) - rust-lang#88847 (platform-support.md: correct ARMv7+MUSL platform triple notes) - rust-lang#88963 (Coerce const FnDefs to implement const Fn traits ) - rust-lang#89376 (Fix use after drop in self-profile with llvm events) - rust-lang#89422 (Replace whitespaces in doctests' name with dashes) - rust-lang#89440 (Clarify a sentence in the documentation of Vec (rust-lang#84488)) - rust-lang#89441 (Normalize after substituting via `field.ty()`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
The documentation for
Vec
states:Here, "its buffer may simply be reused" is simply meant to refer to the behavior of the underlying allocator. But I have seen people with low-level experience be misled by this into thinking that the implementation of
Vec
itself has its own global allocation cache. They then thought this cache was responsible for excess memory usage in their programs.I'm not sure what the best way to clarify this would be. Part of the reason the current wording can be misleading is that "reused by another
Vec
" suggests a mechanism specific toVec
. On the other hand, it would also help to just explicitly mention the allocator. Here is a possible version that addresses both points, but it's more wordy than the current version:The text was updated successfully, but these errors were encountered: