top | item 44048565

(no title)

briansm | 9 months ago

Pardon my ignorance, but I thought the whole point of Rust was to be a 'safe' modern alternative to C, so all new buffers would be zero'd at a neglible-these-days cost. Why is rust half-assing this?

discuss

order

arlort|9 months ago

The cost might not be negligible for everyone?

Rust is being used and is designed to be able to be used everywhere from top of the line PCs, to servers to microcontrollers to virtual machines in the browser.

Not all tradeoffs are acceptable to everyone all of the time

mrkeen|9 months ago

Other languages can easily achieve this kind of safety. What makes Rust different is that it tries to provide this level of safety without doing extra work at runtime (because otherwise people will put it in the same pile as Java/C#, and continue using C/C++ for speed).

vlovich123|9 months ago

It’s not. That is the case. But in cases where “negligible-these-days” isn’t quite negligible enough, this still matters and unsafe + MaybeUninit is the escape hatch to accomplish it.

Arnavion|9 months ago

Also not every type has a valid "all zeroes" value in the first place.

briansm|9 months ago

Yuck. In my mind, 'using C and not using Rust in the first place' is the escape hatch and Rust shouldn't even go there. Jeez, what a mess.

cozzyd|9 months ago

what if your buffer is 64 GiB? (ok, in practice it will be zero'd on demand by the OS but still)

josephg|9 months ago

I’d love to know the actual performance impact of zeroing out memory. I bet the performance cost of zeroing out memory ahead of time is negligible in almost all programs.

briansm|9 months ago

Surely the point of Rust is 'safety at the price of performance' and if extra performance is required, don't use Rust. Don't bodge the language to accommodate!