mikejsavage.co.uk • About • Archive • RSS • Thanks for blocking ads! Blocking ads owns: AdGuard for Safari / uBlock Origin for everything else
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: