I think I have a very simple fix that solves fragmentation. Force the size of every buffer and every array to be a power of two. What do you think?

I think your fix suffers from severe internal fragmentation.