Skip to content

Clarify confusing wording on Vec #46879

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

Closed
steveklabnik opened this issue Dec 20, 2017 · 2 comments
Closed

Clarify confusing wording on Vec #46879

steveklabnik opened this issue Dec 20, 2017 · 2 comments
Labels
A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. P-medium Medium priority

Comments

@steveklabnik
Copy link
Member

Originally reported here: https://news.ycombinator.com/item?id=15969317


I don't understand the following sentence:

... it is strongly recommended that you only free memory allocated by a Vec by creating a new Vec and dropping it.

Could someone parse this for me? To me, it reads like "to free memory allocated by a Vec v, create a new Vec w and drop it (i.e., w)".

This is obviously not what it is intended. What's the role of the second Vec? Is this only in a context where v is empty but its memory not yet freed? If so, why wouldn't shrink_to_fit work in that case?

@steveklabnik steveklabnik added E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. P-medium Medium priority A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools labels Dec 20, 2017
@hanna-kruppe
Copy link
Contributor

This refers to unsafe code that e.g. uses Vec::with_capacity to allocate memory, and then mem::forgets the Vec to use the buffer in different ways (e.g., passing it to C, or implement a custom data structure over the allocated memory).

@Manishearth
Copy link
Member

#46884

kennytm added a commit to kennytm/rust that referenced this issue Dec 21, 2017
@bors bors closed this as completed in 52c28ff Dec 22, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. P-medium Medium priority
Projects
None yet
Development

No branches or pull requests

3 participants