Unofficial Hacker News companion — get notified on comment replies, and more.

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

219 points by fanf2 4 days ago | cetra3.github.io | 90 comments on HN | Vote on HN (opens Hacker News) |

View full thread · View on Hacker News

Comment thread (3)

  1. I don't think it's possible to implement thread-local “global” allocators. Since you need to use the same allocator to allocate and deallocate memory, transferring such objects across threads could transfer them to a thread without the right allocator — any data allocated with that allocator would need to be !Send, but the type system doesn't allow types to vary like that based on what allocator is active.
    Replies (1)
    1. >Since you need to use the same allocator to allocate and deallocate memory

      This isn't true for jemalloc. You can allocate from one thread and deallocate on another.

      Replies (1)
      1. That is still 100% true for jemalloc you just misunderstood what OP said. You can’t allocate using jemalloc and deallocate using mimalloc. Which is what could happen if you have custom global allocators per thread.

        Btw nothing stops you from implanting an allocators that has TLS state and counters. You can even have a global allocators that counts per thread and delicates to an arbitrary allocator that may not have those counters.