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

Arena::alloc_copy_inner (at least) should be renamed and made public #18471

Closed
comex opened this issue Oct 30, 2014 · 2 comments
Closed

Arena::alloc_copy_inner (at least) should be renamed and made public #18471

comex opened this issue Oct 30, 2014 · 2 comments
Labels
A-collections Area: std::collections.

Comments

@comex
Copy link
Contributor

comex commented Oct 30, 2014

I think this is small enough not to need a RFC.

Just as we have both box and heap::allocate, Arena has a safe method to construct an object of a fixed-size type, but should also have an unsafe method to allocate an arbitrary number of bytes. This is what alloc_copy_inner currently does (used for types without a destructor), but it is private. It should be made public (and unsafe?) and given a more descriptive name.

It would be nice to have functionality such as custom destructors and a safe way to allocate DSTs in an Arena, but those would require, respectively, some refactoring and placement new in the language. What this issue is asking for, however, is a simple change that doesn't require design work.

@arielb1
Copy link
Contributor

arielb1 commented Oct 31, 2014

You don't "allocate DST-s" in Rust: for trait objects, you allocate a regular struct and then cast the &Struct to an &Trait (or Box<Struct> to Box<Trait>), and for arrays you use something like Vec, which malloc-s a block of memory and creates a &mut [T] with the right length that points to it.

Trait objects already work with arenas, and teaching Vec about them requires allocator traits.

@kmcallister kmcallister added the A-collections Area: std::collections. label Jan 16, 2015
@pnkfelix
Copy link
Member

cc me

bors added a commit that referenced this issue Jan 11, 2016
Fixes #18037 "TypedArena cannot handle zero-sized types".
Closes #17931 "improve chunk allocation scheme used by Arena / TypedArena".
Closes #22847 "TypedArena should implement Send". - N.B. Arena cannot implement Send, since it may contain non-Send values.
Closes #18471 "`Arena::alloc_copy_inner` (at least) should be renamed and made public." - Added `Arena::alloc_bytes`.
Closes #18261 "support clearing TypedArena with the chunks preserved". - Only the largest chunk is preserved.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-collections Area: std::collections.
Projects
None yet
Development

No branches or pull requests

5 participants