3 ms·
> Rust doesn’t allow you to handle memory allocation failure. This is being worked on? I didn’t know this about Rust and it seems odd for a low level language.
by steveklabnik 8y ago
> Rust doesn’t allow you to handle memory allocation failure. This is being worked on? I didn’t know this about Rust and it seems odd for a low level language.
The standard library panics upon allocation failure, but allocation is a library thing, not a language thing. You can handle failure if you do it yourself. Eventually we have a path forward to handling it for those data structures too, but we’re not quite there yet.
This wasn’t a big concern because when you’re doing OS level stuff you’re generally not using the standard library anyway.
- chubot 8y agoOK, thanks for the clarification. C++ also has this issue, because vector<> and so forth can raise std::bad_alloc. So AFAIK basically nobody who writes kernels in C++ uses STL. Although on second thought, I guess you can handle it because it's an exception rather than a panic. But exceptions have other downsides so people don't use them in that domain.
- steveklabnik 8y agoNo problem. And yeah, it’s effectively the same. You can catch panics if you really need to, but it’s certainly not idiomatic generally. (And most OS-level code makes them aborts which cannot be caught.) This is a situation where it would be... fine. Not as nice as making the api fallible from the start.
- anp 8y agoI could have sworn std aborted on allocation failure, not panicked. Am I misremembering?
- steveklabnik 8y agoAh yes, my bad https://github.com/rust-lang/rust/issues/26951 https://github.com/rust-lang/rust/issues/26951