News for hackers. Stuff that matters.
Re:When zero cost abstractions aren't zero cost by the8472 on Tuesday August 10, 2021 @08:31AM (#28127998)
> However, if the type is Copy and all the bytes are zeros, then you know it can be calloc

That's not as easy to check as one would think since Copy types can still contain uninitialized bytes.

Re:When zero cost abstractions aren't zero cost by PoignardAzur on Tuesday August 10, 2021 @03:04PM (#28132836)
Yeah, but in the common case all the uninitialized bytes are in the padding at the end of the struct (since Rust can re-arrange fields).

Especially in a case like in the article, where the type is very small (one byte), and the obstacle is that the author is using a newtype.

Re:When zero cost abstractions aren't zero cost by the8472 on Tuesday August 10, 2021 @03:48PM (#28133362)
Knowing that they usually are at the end doesn't help since you still need to write a general runtime check that expresses "are all the bits for this type zero or uninit". Afaik currently there is no way to do this without causing UB. This would need some new intrinsic.