For example, I wrote like this:
let mut v: Vec<usize> = (0..10).into_par_iter().collect();
If I then push an extra element into v
, it will probably trigger an alloc and copy operation.
So,
- Can I somehow hint rayon about the vector size it
collects
?
- What's more, can I even give rayon a vector and do the same thing?
jofas
2
I think your are looking for IndexedParallelIterator::collect_into_vec
:
use rayon::prelude::*;
fn main() {
let mut v = Vec::with_capacity(12);
(0..10).into_par_iter().collect_into_vec(&mut v);
}
Playground.
4 Likes
system
Closed
4
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.