Open rw opened 4 years ago
There would need to be a version of Rc
that is specialized to bumpalo
or (eventually) Rc
would need to be parameterized by an allocator (and the allocator's lifetime).
This is sort of similar to bumpalo::boxed::Box
, and how it is different from std::boxed::Box
.
But backing up a bit: why do you want to use an Rc
with bumpalo
? The lifetime of objects allocated in bumpalo means that the Rc
wouldn't be 'static
and that the contents would live as long as the bump arena lives, so it seems like using &T
is equivalent but cheaper since it doesn't do reference counting operations.
@fitzgen Thanks for the reply!
As to your question, I may have gotten ahead of myself. What I thought I wanted was bumpalo::rc::Rc<RefCell<MyType>>
. Are you suggesting that something like &'bump RefCell<MyType>
would work instead?
Are you suggesting that something like
&'bump RefCell<MyType>
would work instead?
Yep!
If you need to run MyType
's destructor, then you'd pass around &'bump bumpalo::boxed::Box<RefCell<MyType>>
Is there a recipe for creating an Rc with bumpalo? I'm trying to avoid the heap allocation(s) that happen inside of Rc.
(For reference, using the
Rc::from_box
function still appears to cause heap allocations.)Thanks!