-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Doc idea: Describe which Rust constructs use pointer indirections and which memcpy #576
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
Comments
We specifically have not and do not guarantee layout yet, so that's part of this. We only guarantee structs with repr(c) |
I understand you don't guarantee specific layout, but what about indirection? I think you define that indirectly anyway via |
e.g. I wonder if It compiles as a function argument, but when I try to use it the compiler says "cannot index a value of type But if I do Given how incredibly expensive cache misses are on modern CPUs, it's very important for me to fully understand which types and expressions have hidden pointers. I wouldn't want to pass around pointers to something that's essentially a length+pointer by itself — in such case I'd rather copy the two words than have another pointer indirection, but I'm not quite sure which types are like that. |
This is what I was after: http://cglab.ca/~abeinges/blah/turpl/_book/data.html |
I've realized I don't have intuition about how Rust's constructs like Slices and Vecs are laid out in memory, and thus how much of them are inline in structs, how much can be on stack, how much gets copied around.
I've seen mentions how many fields slices and vectors have, but that's not quite enough to visualize how, e.g.
Option<Box<Vec<T>>>
looks like.Slices are passed to functions as
&[T]
, but does&[&[T]]
make sense? Should it be[[T]]
?I'd love to see some diagrams that show how many pointer indirections are involved in usage of complex types.
The text was updated successfully, but these errors were encountered: