Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added alignment specification for small_vector #47

Closed
wants to merge 1 commit into from

Conversation

@tobias-loew
Copy link
Contributor

commented Mar 27, 2017

Hi,
in order to be able to use small_vectors for SSE aligned doubles, I've
added an alignment specification for small_vector which ensures alignment
of the internal-storage.
The default value of 0 for the new template parameter ensures the original alignment-calculation.

Tobias

added alignment specification for small_vector
added alignment specification for small_vector which ensures alignment
of internal-storage. Default value of 0 retains original alignment
@@ -115,7 +115,8 @@ template <class T, std::size_t Capacity>
class static_vector;

template < class T, std::size_t N
, class Allocator= new_allocator<T> >
, class Allocator= new_allocator<T>
, std::size_t alignment= 0 >

This comment has been minimized.

Copy link
@glenfe

glenfe Mar 28, 2017

Member

If anything, the default value for the alignment value may as well be 1, indicating the minimum alignment value.

This comment has been minimized.

Copy link
@tobias-loew

tobias-loew Mar 29, 2017

Author Contributor

Hi,
I've deliberately defaulted alignment to 0 to be able to also align the storage below its natural alignment. I don't have any applications for that right now, but since the dynamic allocator has the ability, I thought it could be an option...

static const std::size_t s_align = container_detail::alignment_of<Storage>::value;
typedef small_vector_base<T, Allocator, alignment> svh_type;
typedef vector<T, small_vector_allocator<Allocator, alignment> > svhb_type;
static const std::size_t s_align = alignment > 0 ? alignment : container_detail::alignment_of<Storage>::value;

This comment has been minimized.

Copy link
@glenfe

glenfe Mar 28, 2017

Member

With alignment defaulting to 1, this expression should just also be static const std::size_t s_align = max_size<alignment, alignment_of<Storage>::value>::value; or similar.

@igaztanaga igaztanaga closed this in 4c348af May 9, 2019

@igaztanaga

This comment has been minimized.

Copy link
Member

commented May 9, 2019

Thanks for the report. I've added options to small_vector with the same philosophy as vector/deque/static_vector options. small_vector now can receive two options:

inplace_alignment: similar to your proposal, the alignment for the inplace storage can be proposed.
growth_factor: the growth factor for the dynamic allocation, the same option that can be specified in vector.

Many thanks for the proposal.

Lastique added a commit to Lastique/container that referenced this pull request May 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.