Fighting fragmentation in custom memory manager

2k Views Asked by At

I've written a c/c++ memory manager for heap allocations (overloaded new/delete and malloc/realloc/free, based on Doug Lea's malloc but designed to be wait free) and seem to be having some trouble with fragmentation. Are there any good resources out there that detail good strategies for avoiding fragmentation via the manager?

Please note that I can't rearrange memory that has already been allocated (not using smart pointers with GUIDs) and re-writing the system to use pools instead of heap allocations is unfeasible.

Thanks,
Grant

2

There are 2 best solutions below

0
On BEST ANSWER

You may want to get some inspiration from jemalloc (http://people.freebsd.org/~jasone/jemalloc/bsdcan2006/jemalloc.pdf) - this allocator is used in the new Firefox explicitly because of its anti-fragmentation capabilities.

1
On

Have a look at how more mature projects like glibc do it.

A quick Google finds this, with a stack of references.