Shrink the size of a Ref
in memory for some B: ByteSlice
#368
Labels
compatibility-nonbreaking
Changes that are (likely to be) non-breaking
experience-hard
This issue is hard, and requires a lot of experience
help wanted
Extra attention is needed
Currently
Ref
is defined as:zerocopy/src/lib.rs
Line 1417 in 52ffa4d
This has the consequence that, even if
T: Sized
, when in principleRef
could be a single-word thin pointer,Ref
is still as large asB
. Usually this is two words (e.g. for&[u8]
), but sometimes it's more (e.g. forcore::cell::Ref
, which has a reference count).For some types, this is unavoidable. E.g., no matter what we do, we need to store the entire
core::cell::Ref
- if we didn't, we'd be leaking memory. But for some types - such as&[u8]
- we can reconstruct the originalB: ByteSlice
just from a pointer toT
.Thus, I propose the following addition to
ByteSlice
:Then, we update
Ref
:cc @kupiakos , I know you were interested in having this, and I remember you mentioned taking a stab at some ideas for how to implement it
The text was updated successfully, but these errors were encountered: