-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
docs: Wording regarding guarantees about Vec's unused capacity is unclear #37746
Comments
That approach is fairly pervasive in unsafe code, so it seems like something we'd realistically never be able to break. I'm not totally sure what we would end up using that space for, either. I think we can minimally ensure that this exact approach is allowed - stating that writing to unused capacity and then adjusting the length is valid. |
cc @rust-lang/libs |
@sfackler what you mentioned sounds good to me, seems nice that we shouldn't loosen the restrictions here too much but it's also the case that we'd never break this in any case. |
@sfackler well, I can come up with various hypothetical uses -- such as temporary storage during operations moving parts of the The ideas admittedly are becoming more contrived if only looking at Thinking further, my understanding is that the reserved capacity doesn't really guarantee the specified amount of memory to actually be usable; but rather only that it can be made available during vector growth without moving. (I.e. essentially just reserving part of the address space.) That doesn't really mean anything for the current implementation, working on top of So what I'm saying is that giving any guarantees about availability of the spare capacity definitely does constrain the design space -- though whether that's considered a real concern is a different question of course :-) |
Fix up vec guarnatee around capacity Fixes rust-lang#37746 r? @rust-lang/libs
Fix up vec guarnatee around capacity Fixes rust-lang#37746 r? @rust-lang/libs
The "Guarantees" section in the documentation for
Vec
has some unclear wording, especially in the second-to-last paragraph:In my reading, that means we are explicitly not allowed to store anything (e.g. via FFI calls) in the
Vec
's unused (but allocated) capacity, beyond its current valid length (size) -- but some others are disagreeing with my interpretation.Specifically, the question is whether doing something like this is invalid:
As opposed to this variant, which should be valid even in my reading:
The text was updated successfully, but these errors were encountered: