Unofficial Hacker News client - receive Push Notifications on replies.

The state of Rust allocators in 2026: stabilised (opens external site)

180 points by fanf2 2 days ago | cetra3.github.io | 73 comments on HN | Vote on HN (opens Hacker News)

View full thread · View on Hacker News

Comment thread (20)

  1. When you need it, you need it for the whole program (including all the dependencies).
    Replies (3)
    1. rust has GlobalAlloc
      Replies (1)
      1. Which is useless if you don't want any dynamic allocation at all.
        Replies (2)
        1. 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
          Replies (2)
          1. 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.
            Replies (2)
            1. Why not use an LLM to help with the actual syntax while you only need to worry about the data flow? I've found they're quite good with that.

              Continue this thread (1 replies) →

            2. ...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
          2. Huh, that's a thing? I thought there was just `no_std` and then you can simply leave out `extern crate alloc`.
            Replies (2)
            1. 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
            2. It's exactly as you describe. No_alloc is just no_std without using alloc crate.
        2. If you don't want any allocation at all, you don't need an allocator API.

          But the global allocator is the response to your previous comment:

          > When you need it, you need it for the whole program (including all the dependencies).

    2. 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.

      Replies (1)
      1. >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.

        Replies (4)
        1. 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
        2. Even performance critical applications have non-performance critical parts.

          E.g. in the aforementioned audio programming you may do the setup, init phase normally and only go for custom allocators afterwards.

        3. 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.

        4. Rust is kind of targeting those users. I want Rust to cater to this usecase. It is fine not to use custom allocators if you don’t want to.
    3. 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.