alignment.cpp 773 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
#include "pls/internal/base/alignment.h"

namespace pls {
namespace internal {
namespace base {
namespace alignment {

system_details::pointer_t next_alignment(system_details::pointer_t size,
                                         size_t alignment) {
  return (size % alignment) == 0 ?
         size :
         size + (alignment - (size % alignment));
}

system_details::pointer_t previous_alignment(system_details::pointer_t size,
                                             size_t alignment) {
  return (size % alignment) == 0 ?
         size :
         size - (size % alignment);
}

char *next_alignment(char *pointer, size_t alignment) {
  return reinterpret_cast<char *>(next_alignment(reinterpret_cast<system_details::pointer_t >(pointer), alignment));
}

}
}
}
}