Re:Choosing a more optimal `String` type
by LegionMammal978 on Saturday September 23, 2023 @12:35AM
(#37620603)
Unfortunately, this can't really be done with how allocation works in Rust. A String is always allocated with alignment 1, but an Arc's control block requires usize alignment. An allocated pointer can't be deallocated with a different alignment, nor can its alognment be changed when reallocating. Thus, the from_raw_parts() idea would be unusable for all types with less than usize alignment.
(And the need for atomic operations on the control block precludes the idea of simply letting it be unaligned.)
(And the need for atomic operations on the control block precludes the idea of simply letting it be unaligned.)