Closed bzm3r closed 1 year ago
- Am I right in understanding that
FrozenVec
will never be re-allocated on resize?
No, it will.
1. why does
FrozenVec
not expose awith_capacity
-like for creating newFrozenVec
s?
It could, it wasn't needed so far. Happy to merge a PR for it.
I think I can make an attempt to answer my questions, based on some thinking + reading of the source.
No, it is not true that the underlying Vec
backing a FrozenVec
will never be re-allocated on resize. (At least, I could not find how this would be prevented, in the source.) **This does not break FrozenVec
's underlying StableDeref
's requirements, because any reference to something held within Vec
is still valid across re-allocation, after all Vec
implement's StableDeref
. (how?)
is moot given 0.
Not sure.
@Manishearth Ah, you beat me to it! 🤣
Now the puzzle in my mind is around how Vec's refs stay stable across re-allocation.
Okay, I missed this: https://docs.rs/elsa/latest/src/elsa/vec.rs.html#40
So, FrozenVec
works because the elements of the underlying Vec
are StableDeref
. That Vec
is StableDeref
is irrelevant, because that only seeks to confirm: "a reference to the Vec
is stable upon its re-allocation" and says nothing about references to the entries of the Vec
. So, this answers all my questions, and makes them moot.
Re: with_capacity
it makes sense that it hasn't come up yet, and I don't think it has come up yet for me either, so its not important. My primary motivation for it was based on no-re-alloc concern I had when I was misunderstanding FrozenVec
.
(This is a discussion, rather than an issue. Can it be converted into one?)
Two questions, about
FrozenVec
:0) Am I right in understanding that
FrozenVec
will never be re-allocated on resize?1) is
FrozenVec
more prone to fragmentation issues as it grows, since it will never be re-allocated on resize?2) why does
FrozenVec
not expose awith_capacity
-like for creating newFrozenVec
s?(Thank you! 🙏)