One way around this is to allocate in slabs, adding a new slab when needed. A small system might allocate one slab, whereas a bigger one might allocate, say, four.
honey the codewitch wrote:The trouble here is determining the pool size up front without just making it the size of available memory.
If the memory manager uses buddy allocation and you allocate temporary memory and then free it all before allocating more, fragmentation should be avoided altogether.
honey the codewitch wrote:One thing I am doing is playing hot potato with my RAM to avoid fragmentation. I do not keep little allocations around.
An excellent strategy that is also important in systems where latency must be predictable.
honey the codewitch wrote:Allocations that are kept around are allocated up front.