-
Notifications
You must be signed in to change notification settings - Fork 1
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
A single lifetime parameter in BumpVec
#2
Comments
I think this would prevent code like this: let slice = bump_vec![in bump; 1, 2, 3].into_slice();
let foo = bump.alloc_str("whatever"); I we had just the one lifetime, |
The idea is that you can push items to a |
Interesting. So if |
Generally not with use bump_scope::{ Bump, allocator_api2::vec::Vec };
let bump: Bump = Bump::new();
let mut vec: Vec<&str, _> = Vec::new_in(&bump);
for _ in 0..10 {
let string = bump.alloc_str("hello").into_ref();
vec.push(string);
}
dbg!(&vec);
Edit: code example works now |
What advantage does |
Its just that the capacity is initialized with the space left in the chunk. So you get less realloc calls. |
Interesting. I wonder if the difference would be observable in benchmarks. I didn't realize that |
Another thing to consider is that you could get the exact same property (capacity is initialized with the space left in the chunk) like this: use bump_scope::allocator_api2::Vec;
Vec::with_capacity_in(bump.stats().remaining()/size_of::<T>(), bump) But without the need of a separate type that requires exclusive access. |
I have not delved into it too deeply, but it seems like it should be possible to only have one lifetime parameter for
BumpVec
(and by extensionBumpString
). This is similar to bumpaloVec
. The lifetime is there to ensure that it either does not outlive theBump
or theBumpScopeGuard
, depending on if the scope is present. It seems like a single lifetime could serve both purposes. However just changingBumpVec
to this:Would make it invariant over
'a
, which is probably not desirable.The text was updated successfully, but these errors were encountered: