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
The size of Arc is guaranteed to be the size of a single pointer, which is cool. Also, being more realistic, it means that if you have a non-zero-sized allocator, you don't have to pay the cost of its size on each clone of the instance, instead the allocator is stored in the inner pointer. That means that multiple copies of the same instance won't require multiple copies of the allocator, saving memory unlike the current approach,
Doing this also means that A doesn't require implementing Clone if you want to clone the Arc, since it's stored in the shared pointer. This would relax the current Arc cloning implementation, no longer requiring A: Allocator + Clone but only A: Allocator. It would probably relax the same constrain in make_mut, unwrap_or_clone, downcast, downcast_unchecked, From<Vec<T, A>> for Arc<[T], A> and TryFrom<Arc<[T], A>> for Arc<[T; N], A>.
The text was updated successfully, but these errors were encountered:
Basically, at the moment
Arc<T, A>
uses:(Something similar happens in
Rc
, so this whole issue could also be applied toRc
.)My idea is to move
alloc
fromArc
toInnerArc
:This would produce 2 benefits:
Arc
is guaranteed to be the size of a single pointer, which is cool. Also, being more realistic, it means that if you have a non-zero-sized allocator, you don't have to pay the cost of its size on each clone of the instance, instead the allocator is stored in the inner pointer. That means that multiple copies of the same instance won't require multiple copies of the allocator, saving memory unlike the current approach,A
doesn't require implementingClone
if you want to clone theArc
, since it's stored in the shared pointer. This would relax the currentArc
cloning implementation, no longer requiringA: Allocator + Clone
but onlyA: Allocator
. It would probably relax the same constrain inmake_mut
,unwrap_or_clone
,downcast
,downcast_unchecked
,From<Vec<T, A>> for Arc<[T], A>
andTryFrom<Arc<[T], A>> for Arc<[T; N], A>
.The text was updated successfully, but these errors were encountered: