Not really. Case in point: (soft)realtime audio programming. If you need to allocate memory in the audio callback (or DSP helper threads), you must use a real-time safe allocator (bounded worst case, no mutexes). For the rest of the program you may still use the default system allocator.
My toy kernel says otherwise. There are many stages of boot at varying levels of abstraction and being able to conveniently express each one is wonderful.
Also think of things like embedded scripting languages. Or having a special allocator for physics objects in a game as opposed to GUI objects. Yes, you can use a global allocator tuned to the workload. You can also tune allocators for each one. You don't have to, but you can.
>My toy kernel says otherwise. There are many stages of boot at varying levels of abstraction and being able to conveniently express each one is wonderful.
You need tight allocation control and arena usage when squeezing the most performance possible out of your system is non-negotiable. Most people don't need to write such code.
It's not only about performance. It is also about embedded system that don't have much memory, and have no fallback when they are out of memory. When ending up in some untested and faulty state you'd prefer getting some logs to just panicking and rebooting.
When the code uses dynamic allocation liberally, there is no such option: once a malloc fails you can only panic. You can reserve a piece of memory for recovery action, but it doesn't help much if recovery path engages most of the codebase. E. g. on IoT stuff most of the complexity is in the network stack - and you need the network stack if you want to get your logs.
And yes, recursion and stack is also a problem, even if more manageable than malloc. You can avoid recursion completely, but there still a risk of stack overflow on an untested code path. Zig promised staticaly-known stack depth once, but, afaik, didn't get there.
Object pools are somewhat popular. Hugely popular in game development. And they are essentially a custom allocator for languages that don't have custom allocators
Then you should generally go for `no_alloc`, because std allocates, so no_std + no_alloc leaves you with core + a bunch of crates for no_std data manipulation
Frankly I'm not sure syntactically, didn't have to touch no-std in a bit, so I assume you're right. I do know that no_alloc is a crate tag people use and it's a readable enough way to phrase it
And then I have to deal with writing tons of code to please the borrow checker myself. At which point I might as well go for a language that doesn't need so much ritual.
...in what way is this related? Ownership is ownership, it's always a factor. Allocation is different because if you don't want any dynamic allocation, you don't want an allocator in the first place, ownership is an orthogonal concern
It's not just syntax. Depending on the allocation scheme used it can be very difficult to prove to the borrow checker that it's all safe, or even impossible (the same way some data structures in Rust can only be implemented with `unsafe`).
Agreed, this is why I don't write kernels or things like that in Rust. The borrow checker will assume that your code is running in a parallel (multicore/multithreaded) capable environment, even if it isn't, and there is no way to explicitly tell the borrow checker to stfu, so you have to do a bunch of hack abstractions (Ref<T>, Rc<T>, ...) just to make it shut up.
If you stick to single ownership and stack tied or static lifetimes it's not too bad. If you're trying to pass parameters with lifetimes that extend beyond the stack frame and aren't static, then yes, that is painful. Callbacks or async style code in particular is challenging.