diff --git a/src/ds/address.h b/src/ds/address.h index 66e0fcd..4b61e50 100644 --- a/src/ds/address.h +++ b/src/ds/address.h @@ -88,6 +88,22 @@ namespace snmalloc #endif } + /** + * Align a pointer up to a dynamically specified granularity, which must + * be a power of two. + */ + template + inline T* pointer_align_up(void* p, size_t alignment) + { + assert(alignment > 0); + assert(bits::next_pow2(alignment) == alignment); +#if __has_builtin(__builtin_align_up) + return static_cast(__builtin_align_up(p, alignment)); +#else + return pointer_cast(bits::align_up(address_cast(p), alignment)); +#endif + } + /** * Compute the difference in pointers in units of char. base is * expected to point to the base of some (sub)allocation into which cursor