Open frankmcsherry opened 9 years ago
I have used this crate in my private database project a ~while~ some years back and sometimes I get back to this issue, as it was the one thing I really needed to recycle: a buffer of log entries needed to be written/flushed to a log. The difficulty was that these log entries held references to data blobs which lived on a Bytes from bytes crate.
If anyone is looking to recycle a Vec<LogEntry<'a>>
or similar, I do not know if you can put the recycler behind a nice API, but taking the vec apart into raw values and rebuilding it once again might work wonderfully, as hinted in the original issue description. And as long as the vec is cleared before taking it apart, I think this use of unsafe
might be perfectly safe :)
It would be nice to be able to recycle types with lifetimes in them. Right now this is an issue, because maintaining e.g. a pool of
Vec<&'a T>
for longer than'a
is a problem, even though we know that the vectors are all empty, and so contain no references to invalid memory. Perhaps this is as easy as makingVecRecycler<R>
not have aVec<Vec<R::Item>>
field but rather one of typeVec<UntypedVec>
, which doesn't reveal lifetimes ofR::Item
. This would surely require someunsafe
, so ... maybe let's ponder that for a bit.