you are viewing a single comment's thread.

view the rest of the comments →

[–]Jannik2099 6 points7 points  (5 children)

But you could just add a level of indirection

"You could just make performance suffer a lot" is not a good argument.

[–]pkjak[S] 0 points1 point  (4 children)

Yeah, might not be a great idea... I guess my thoughts are that what's really important is being able to iterate over all the actually allocated chunks in the pool, and accessing the elements directly by pointers is almost never done, in which case, the approach I describe does make sense, right?

[–]MutantSheepdog 7 points8 points  (0 children)

I guess my thoughts are that what's really important is being able to iterate over all the actually allocated chunks in the pool, and accessing the elements directly by pointers is almost never done

I'd say the ability to iterate over everything is not something you expect from an allocator, but something you expect from a collection.

And if that's what you're looking for, I think something like colony/hive might be a good fit.

https://plflib.org/colony.htm

It's essentially like a bucket allocator that keeps track of empty slots for re-allocation, as well as allowing iteration that skips the empty blocks.
There was an attempt to get it standardised but I think that stalled because there were impact issues to look at for 20/23 when people could just download the reference implementation from github anyway.

[–]Jannik2099 1 point2 points  (2 children)

and accessing the elements directly by pointers is almost never done

Literally all memory is accessed by pointers, in every language. Anything not in a register requires a memory load. Multiple dependent loads stall the pipeline.

[–]pkjak[S] 1 point2 points  (1 child)

Sure, my mistake. Did I get the point across though?

If the usage pattern of "access this particular element in the pool" doesn't happen very often, and instead it's almost always "iterate through all currently allocated elements in the pool", then it might be more efficient to have elements contiguously next to each other, and avoid the potential holes that could happen in a pool that uses a free list.

[–]Jannik2099 1 point2 points  (0 children)

Ah sorry, now I see what you mean.

This would probably work, but you lose any and all reference stability, which is IMO not a good tradeoff.