-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Add Vec visualization to understand capacity #76066
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
Changes from 1 commit
9c1415e
ea337c6
f2bd46b
53af7b8
a919516
55ad7f2
44e9b7f
6900744
79918c1
62ba5b1
702662e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -194,6 +194,19 @@ use crate::raw_vec::RawVec; | |
/// can be slow. For this reason, it is recommended to use [`Vec::with_capacity`] | ||
/// whenever possible to specify how big the vector is expected to get. | ||
/// | ||
/// In summary, a vector containing 1, 2 with capacity 4 can be visualized as: | ||
/// ```text | ||
/// Stack +--------+--------+--------+ | ||
/// | ptr |capacity| len | | ||
pickfire marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// | 0x0123 | 4 | 2 | | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is intentionally different, see #76066 (comment). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jyn514 That comment suggests to use a different layout than the real layout. The 'real' layout is (RawVec, len), which is effectively a (ptr, cap, len). Changing it to (ptr, len, cap) as I suggest does make it different from the actual layout, just like the8472 asked for. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Weird, I didn't notice this, I thought I used |
||
/// +--------+--------+--------+ | ||
/// | | ||
/// v | ||
/// Heap +--------+--------+--------+--------+ | ||
/// | 1 | 2 | | | | ||
/// +--------+--------+--------+--------+ | ||
pickfire marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// ``` | ||
/// | ||
/// # Guarantees | ||
/// | ||
/// Due to its incredibly fundamental nature, `Vec` makes a lot of guarantees | ||
|
Uh oh!
There was an error while loading. Please reload this page.