Yup, malloc/free isn't usually algorithmically expensive but the cache misses tend to be the brutal part.
You'll spend 15 cycles doing work on 600 cycles of cache fetching. Plus you've just evicted some cache for your local scope.
You'll spend 15 cycles doing work on 600 cycles of cache fetching. Plus you've just evicted some cache for your local scope.
The allocation itself is not the bottleneck, it's the poor choice of data structure.