calgorithmmemory-managementmemory-fragmentation

write my own memory manager


I would like to allot some huge dynamic memory and then write my own memory manager for it. i.e. As and when my code needs memory, I'd allot from this pool of memory. I want the algorithm to take care of internal and external fragmentation. Which is the most efficient algorithm for this?


Solution

  • For these criteria I'd go with Doug Lea's http://g.oswego.edu/dl/html/malloc.html, which maintains collections of blocks of store for each of a number of different sizes - it's quick to find the size you need, and reusing blocks of the same size reduces fragmentation. Note (http://entland.homelinux.com/blog/2008/08/19/practical-efficient-memory-management/) that this is NOT tuned for multi-threading.

    If I was writing one myself I'd go for the http://en.wikipedia.org/wiki/Buddy_memory_allocation because it's fast and not commonly used in user space (not commonly used because it restricts the possible block sizes, leading to internal fragmentation). In fact, I did, some time ago - http://www.mcdowella.demon.co.uk/buddy.html