lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


> Specifically, I can see lots and lots of realloc calls with a one byte difference between the old block size and the new block size, in both directions (+1 or -1 difference).
 
When implementing your allocator, save the block size away with the block returned. And then when a block is downsized, if it's within 16 bytes or 25% of the allocated size, don't move it - just downsize "in place". Similarly when upsizing, if it cannot be satisfied in place add say 50% to the new block size. Such heuristics minimize memory moves and fragmentation quite nicely. Note, it's wise to use percentage sizes along with minimum deltas. Otherwise you're only fixing the problem for small resizes.
 
- Alex