Lokathor / bytemuck

A crate for mucking around with piles of bytes
https://docs.rs/bytemuck
Apache License 2.0
738 stars 80 forks source link

Improve `fill_zeroes`' use of `ptr::write_bytes` #284

Closed a1phyr closed 1 week ago

Lokathor commented 3 weeks ago

Looks like these are deliberately two lines to prevent the length check (using &self) from invalidating the mut pointer.

a1phyr commented 3 weeks ago

Nice catch! It doesn't seem to annoy MIRI though: https://play.rust-lang.org/?edition=2021&gist=3ffc5bffdb51903f2613413470953084

Lokathor commented 1 week ago

released in bytemuck-1.20

thomcc commented 1 day ago

I think the old version filled padding with zeroes, but the new one isn't guaranteed to.

Lokathor commented 1 day ago

write_bytes is similar to C’s memset, but sets count * size_of::() bytes to val.

https://doc.rust-lang.org/core/ptr/fn.write_bytes.html

and the size of T includes any tail padding

so i think this is the same?