You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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.
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.
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 whatalloc_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.
The text was updated successfully, but these errors were encountered: