Skip to content
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

Recipe for Rc? #84

Open
rw opened this issue Sep 3, 2020 · 4 comments
Open

Recipe for Rc? #84

rw opened this issue Sep 3, 2020 · 4 comments

Comments

@rw
Copy link

rw commented Sep 3, 2020

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!

@fitzgen
Copy link
Owner

fitzgen commented Sep 9, 2020

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.

@rw
Copy link
Author

rw commented Sep 10, 2020

@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?

@fitzgen
Copy link
Owner

fitzgen commented Sep 10, 2020

Are you suggesting that something like &'bump RefCell<MyType> would work instead?

Yep!

@fitzgen
Copy link
Owner

fitzgen commented Sep 10, 2020

If you need to run MyType's destructor, then you'd pass around &'bump bumpalo::boxed::Box<RefCell<MyType>>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants