views:

489

answers:

2

Hi,

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

+1  A: 

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.

Paul Betts
A: 

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

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

Adam Hawes
FWIW, dlmalloc is quite mature. Doug Lea has been working on it since 1987. Furthermore, he was the primary maintainer of the GNU C++ library (libg++). If you use the "standard" malloc in many C and C++ libraries, you are already using dlmalloc.
Adisak