29 Nov 2023 • C++ tricks: Production Ready TM aligned malloc

People generally implement aligned malloc by adding some metadata at ptr[-1] pointing to the actual allocation. In this post I will show you a simpler way.

void * Allocate( size_t size, size_t alignment ) {
    Assert( alignment <= 16 );
    return malloc( size );

This works because: