-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Add some more OOM-handling Box<[T]> constructor variants
#12441
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
Add some more OOM-handling Box<[T]> constructor variants
#12441
Conversation
7d4e831 to
de2a430
Compare
alexcrichton
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another possible idea:
- One function to return
fn(usize) -> Result<Box<[MaybeUninit<T>]>> - Another function
fn(Iterator<T>, Box<[MaybeUninit<T>]>) -> Result<Box<[T]>> - Another function for a fallible iterator
- Helper functions combining these together
This is sort of what we have, except we don't expose the second function publicly, just as an implementation detail. What these proposed functions don't collectively cover, however, is when you have an unknown-length iterator, unless I am misunderstanding. |
de2a430 to
ec6e508
Compare
ec6e508 to
bdcf42e
Compare
cfallin
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks correct to me; I think my main question (in addition to the one naming thought below) is why we need to define an error case TooFewItems. I suppose I'm not seeing the callsite(s) here but naively I would expect, given that we've implemented the shrink_to_fit logic, we could always use that if an iterator returns fewer items than expected; do we have cases where we want to guard against that (reallocation) wastefulness and flag a logic error instead?
Basically, yes. We have call sites that know the exact length of various things but which also do not have |
bdcf42e to
f9076a5
Compare
Need to forget `self` or else we will double-free the buffer.
4257de4 to
fd976b8
Compare
Part of #12069