dynamic allocator that has no knowledge of alignment, can be used to provide aligned buffers, at the price of a factor two in space loss. // Example: get 4096 bytes aligned on a 4096 byte buffer with malloc() // unaligned pointer to large area void *up = malloc((1 << 13) - 1); // well-aligned pointer to 4 KiB void *ap = aligntonext(up, 12); where aligntonext(p, r) works by adding an aligned increment, then clearing the r least significant bits of p. A possible implementation is // Assume `uint32_t p, bits;` for readability #define alignto(p, bits) (((p) >> bits) << bits) #define aligntonext(p, bits) alignto(((p) + (1 << bits) - 1), bits) Notes References Further reading External links IBM developerWorks article on data alignment Article on data alignment and performance MSDN article on data alignment Article on data alignment and data portability Byte Alignment and Ordering Stack Alignment in 64-bit Calling Conventions - discusses stack alignment for x86-64 calling conventions The Lost Art of Structure Packing by Eric S. Raymond Compiler construction Composite data types