Need help?
<- Back

Comments (83)

  • atombender
    I use Jemalloc in a specific project because it keeps per-thread allocation counters, so I can both monitor how much memory a thread is actively using (and how much it has allocated and deallocated), and I can limit it.This is an incredible feature, and it's a hard requirement for this particular project, and a good fit because the workloads map to threads. Manually managing such counters with the standard Rust allocator is not a practical option.But one problem I see with the new Rust allocators is that it doesn't seem like there's any kind of thread-local allocator? If so, you have to pass an allocator through every nook and cranny of the system as opposed to just riding on the thread context.Even if the allocator is available as a "global" thread-local variable, which might be an option, that's a lot of places that need to be updated with .new_in(). And you have to introduce some kind of linting rule that rejects any code that isn't using the custom allocator.I don't suppose a solution to this problem exists or is planned?
  • ozgrakkurt
    Good luck to all people who are going to try implementing allocators!Last time I tried, even the standard containers were giving different layouts to allocate and deallocate.Also as a bonus, you get to put another template parameter to all of your containers!
  • gwbas1c
    > Instead, what if we knew that we would have a period of time in our code, where we're going to allocate a lot of stuff, do something with it, and then free everything? A good example of this is a web request, or a database query.> A request comes in, fills in some data structures, and then when the request finishes, the memory isn't needed anymore so it's dropped. This sort of "burst" pattern of allocation, where you allocate a lot up front, and then tear things down all at once at the end, is quite common.FYI: Generational garbage collectors, such as the one used in the dotnet framework since the beginning (~2002), are very good at handling this.Basically, the 0 generation starts as a large chunk of memory, and before a slow "mark and sweep" the reachable objects that are in the 0 generation are copied to the 1 generation. This implicitly deallocates unreachable objects in the 0 generation.(Then again, there are a lot of tradeoffs to using a garbage collected language vs. Rust. I find that a program in Rust, vs an equivalent in C#, has a significantly lower RAM footprint.)
  • slopinthebag
    at this point I don't see much argument for languages that make allocators explicit. the escape hatch is there in rust for the rare case when you need it, and you get safety and all of rust's other benefits now too. well done to the rust core team to get this stabilised.
  • xiaogui917
    The part I find most important here is the ecosystem effect: once Allocator is stable, libraries can be allocator-agnostic without splitting the ecosystem between nightly and stable crates. That should make it much easier for a database, game engine, or embedded project to plug in its own allocation strategy without forking every dependency. For most applications the default allocator will still be the right choice, but having a stable, shared interface is what turns custom allocation from a niche trick into ordinary infrastructure.
  • NooneAtAll5
    so... what exactly was changed from straight-forward implementation of the feature that has been "unstable" for so many years?
  • speedgoose
    > It's going to take a bit of time for the ecosystem to catch up to custom allocators.I havn't published any popular rust crate. I think my crates are downloaded by me and robots only, so I don't have a lot of authority. I have no wishes to think about custom memory allocators. I don't want them. I consider those as unnecessary complexity for a niche use case, and I'm a bit annoyed that they will pollute the Rust landscape. I understand why people need them though, but I fear that Rust is going to be the next C++: a bloated programming language with features to please everyone and a lack of simplicity. It's already complex enough.
  • YKupriyanov
    [dead]
  • ReDress
    [dead]
  • neumeisterfrank
    [flagged]