def _get_padding(alignment, current_size, next_element_size):
    """Calculate number of padding bytes required to get next element in
    the correct alignment
    """
    if alignment == 1:
        return 0  # Always aligned

    elem_size = min(alignment, next_element_size)
    remainder = current_size % elem_size
    if remainder == 0:
        return 0
    return elem_size - remainder