First of all, if you do not have a measured problem with memory usage, don't even think about using a custom allocator. This is one of the worst forms of premature optimization.
At the same time, even if you have problems, a better solution than a custom allocator will determine why you allocate and free objects so much, and fix the design problem that causes it.
To solve your specific question, the glibc allocator is based on the dlmalloc algorithm, which is almost optimal when it comes to fragmentation. The only way you get it for poorly fragmented memory is the inevitable way: by placing objects with radically different lifetimes in alternation, for example. highlighting a large number of objects, but only freeing each other. I think it will be difficult for you to develop a distribution pattern that will give worse overall memory usage than pools ...
source share