15 return ((alignment > 0) && ((alignment & (alignment - 1)) == 0));
21 assert((address !=
nullptr) &&
"Address must be valid!");
22 assert(IsValidAlignment(alignment) &&
"Alignment must be valid!");
24 uintptr_t ptr = (uintptr_t)address;
25 return (ptr & (alignment - 1)) == 0;
29 inline T*
Memory::Align(
const T* address,
size_t alignment,
bool upwards) noexcept
31 assert((address !=
nullptr) &&
"Address must be valid!");
32 assert(IsValidAlignment(alignment) &&
"Alignment must be valid!");
34 uintptr_t ptr = (uintptr_t)address;
37 return (T*)((ptr + (alignment - 1)) & -((int)alignment));
39 return (T*)(ptr & -((int)alignment));
static bool IsValidAlignment(size_t alignment) noexcept
Is the given alignment valid?
static bool IsAligned(const T *address, size_t alignment=alignof(T)) noexcept
Is the given pointer aligned?
static T * Align(const T *address, size_t alignment=alignof(T), bool upwards=true) noexcept
Align pointer (upwards or downwards)
C++ Common project definitions.