Uh oh!
There was an error while loading. Please reload this page.
Add doc aliases for memory allocations - #79233
Conversation
rust-highfive
commented
Nov 20, 2020
(rust_highfive has picked a reviewer for you, use r? to override) |
This is a great idea! For Also consider aliases for I'd love to see PRs like this for other common C functions as well, such as the |
Uh oh!
There was an error while loading. Please reload this page.
yoshuawuyts
commented
Dec 18, 2020
I've updated with @joshtriplett's feedback. @Manishearth@GuillaumeGomez did you resolve the conversation in #79211? -- I'm tempted to tag both libs and docs on this for review, but wanted to check before doing so. |
Manishearth
commented
Dec 18, 2020
@yoshuawuyts yeah mostly "ping both @GuillaumeGomez and the libs team for doc changes". Hopefully they can form a libs-docs team eventually. Feel free to tag the docs team, it's just kinda defunct right now and you'd be tagging more people than you need. |
GuillaumeGomez
commented
Dec 18, 2020
No need. Just |
yoshuawuyts
commented
Dec 18, 2020
Got it, thanks heaps! |
bors
commented
Dec 31, 2020
☔ The latest upstream changes (presumably #80530) made this pull request unmergeable. Please resolve the merge conflicts. |
crlf0710
commented
Jan 15, 2021
Triage: there's merge conflicts now. |
yoshuawuyts
commented
Jan 15, 2021
Oh dang, this is because of the new |
yoshuawuyts
commented
Jan 22, 2021
Resolved the merge conflicts; a simple rebase was enough. This is again ready for review! |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Even though this realloc alias makes sense, having so many of it is kinda killing its purpose, no?
There was a problem hiding this comment.
Rust has no canonical "realloc" function; instead it's split up between various different methods which perform specific kinds of reallocations. Someone searching for "realloc" may not be aware of this, and sharing the various ways in which vectors can be reallocated may be helpful.
Conversely an experienced Rust programmer may not recall the exact name of a specific reallocation they're trying to perform (or may want to validate whether a vec method indeed reallocates) and searching for "realloc" may provide them with an answer.
There was a problem hiding this comment.
Fine by me, let's give it a try like this then!
Uh oh!
There was an error while loading. Please reload this page.
- Vec::with_capacity / Box::new -> alloc + malloc
- Box::new_zeroed -> calloc
- Vec::{reserve,reserve_exact,try_reserve_exact,shrink_to_fit,shrink_to} -> reallocGuillaumeGomez
commented
Jan 22, 2021
Thanks! @bors: r+ |
bors
commented
Jan 22, 2021
📌 Commit 7d10238 has been approved by |
bors
commented
Jan 22, 2021
bors
commented
Jan 23, 2021
☀️ Test successful - checks-actions |
This patch adds doc aliases for various C allocation functions, making it possible to search for the C-equivalent of a function and finding the (safe) Rust counterpart:
Vec::with_capacity/Box::new/vec!-> alloc + malloc, allocates memoryBox::new_zeroed-> calloc, allocates zeroed-out memoryVec::{reserve,reserve_exact,try_reserve_exact,shrink_to_fit,shrink_to}-> realloc, reallocates a previously allocated slice of memoryIt's worth noting that
Vec::newdoes not allocate, so we don't link to it. Instead people are probably looking forVec::with_capacityorvec!. I hope this will allow people comfortable with the system allocation APIs to make it easier to find what they may be looking for.Thanks!