Aligned allocations


It would be nice if we had some way to request that the allocations made by pd->system->realloc have a particular alignment, so that we could make sure they line up neatly with cache lines.

Alternatively, if realloc already guarantees some alignment, it'd be good if that could be documented :slight_smile:

Right now, if the allocation I get is not aligned, I am taking a 'cross my fingers and hope' approach of "compute how much padding is needed at the start, realloc the block down to that size, then try the original allocation again in the hope that it gets placed linearly after the padding block." This is still not guaranteed to give me an aligned block, but at least it means I can free the padding and potentially use it for something else. If there's a more reliable trick that I'm missing, let me know!

Of course the other alternative is to just try and allocate the entire heap at startup and then manage things myself, but a) I'm not sure whether the other PD API methods would be OK with that (like I assume file I/O allocates memory, etc) and b) I'd lose the ability to use the malloc tracker.


Hello Richard! Long time no see!

1 Like