News for hackers. Stuff that matters.
Re:Custom Allocators in Rust by stephc_int13 on Saturday April 08, 2023 @11:22AM (#35494129)
I think that avoiding global allocation and lifetime management is good design and a way to make memory management as simple and flexible as it should.

But, from my own work in the field, I came to the conclusion that there is a better way than passing custom allocators: passing containers instead.

In practice this is almost the same thing (except that containers are made to be easily traversed) but semantically there is a subtle and positive difference.

The goal is to avoid confusing the allocating policy (let's say arena versus heap) with the allocator instance.

Re:Custom Allocators in Rust by conaclos on Saturday April 08, 2023 @01:26PM (#35495545)
What do you mean by Containers?

A good abstraction for passing allocators could be effect and effect handler.

Re:Custom Allocators in Rust by stephc_int13 on Saturday April 08, 2023 @01:38PM (#35495681)
A container is basically a structure holding a collection.

In that case, the container also acts as an allocator (the feature can be embedded directly or not)

The only practical difference is that a container should provide some facilities for traversal, while the allocator is only taking care of allocating and freeing.

From my experience, I very rarely allocate things without keeping them in a kind of container, it can be something as simple as an array of references.