Skip to navigation

hololink::module::round_up

View as Markdown
inline size_t hololink::module::round_up(
size_t value,
size_t alignment
)

Round a value up to a multiple of an alignment.

Used to size and place buffers so they start and end on the boundaries the hardware or an API requires, for example round_up(size, PAGE_SIZE).

The alignment may be any positive value; it need not be a power of two. A value that is already a multiple of alignment (including zero) is returned unchanged.

Returns: The smallest multiple of alignment that is not less than value.

Throws: std::runtime_error if alignment is zero.

Throws: std::overflow_error if the rounded result is too large to be represented in a size_t.

Parameters

value
size_t

The size or offset to round.

alignment
size_t

The multiple to round up to. Must be greater than zero.