3 ms·
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, fr
by stephc_int13 4y ago
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.
- conaclos 4y agoWhat do you mean by Containers? A good abstraction for passing allocators could be effect and effect handler.
- stephc_int13 4y agoA 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.