-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Possibility of exposing RcBox
for transferring allocations between Box
and Rc
#1283
Comments
@eddyb Has some ideas for how custom allocator support can make this easier, without having to expose anything. |
That would be #1138. |
Even cooler :) |
Why not make the (current) |
|
Errr, GitHub, I didn't want to do that! |
Ah, right. Although I'm sure that could be worked around with some raw pointer shenanigans. But that would invalidate the "no drawbacks" part, because of much uglier implementation. :-/ |
The idea occasionally comes up of whether
Rc
could take ownership of aBox
and re-use the allocation, or conversely of converting a uniquely-ownedRc
into aBox
. While logically intuitive, this runs up against the physical limitation thatRc
stores the reference counts inline in the allocation, ahead of the data, and so the two would not be compatible as-is. MakingRc
store the reference counts out of line in a separate allocation (likestd::shared_ptr
) doesn't seem to be worth the overhead just to support this case.If, however, we were to consider the ability to avoid some allocations in this way important enough, we do have a fairly straightforward option available to us to support it in some cases: publicly expose the
RcBox
type which comprises anRc
allocation (without necessarily providing access to the internalRcBox
of anyRc
- just the type). Something like this:(By keeping the reference count fields private, we can ensure that the reference count of any
RcBox
not currently inside of anRc
is always 1, so thatfrom_box
doesn't even need to check or reset them.)The text was updated successfully, but these errors were encountered: