|
Boost : |
Subject: Re: [boost] small_vector alignment
From: Glen Fernandes (glen.fernandes_at_[hidden])
Date: 2017-03-21 13:55:21
> I wanted to use a boost::container::small_vector for 64-bit aligned
> doubles (to be used with SSE):
>
> typedef boost::container::small_vector<double, 16,
> aligned_allocator<double, sizeof(__m128)> > sse_double_vector;
>
> But it seems that the "small-buffer" has a fixed calculated alignment
> which only depends on the value-type and does not consider the alignment
> of the (dynamic) allocator.
Hi Tobias,
Yes, it looks like small_vector does not expose any mechanism for you to
control the alignment of its internal "small" storage. So you can only
expect that for 'double' the storage is at least alignof(double) aligned.
(The aligned_allocator will only apply after that 'small' storage is
exhausted of course.)
One solution could be to use std::vector instead with
aligned_allocator_adaptor with in conjunction with another custom allocator
for a kind of small-size optimization e.g.
sso_storage<N> s;
std::vector<double,
aligned_allocator_adaptor<sso_allocator<double, N>, alignof(__m128)> >
sse_double_vector(sso_allocator<double, N>(s));
(i.e. The 'sso_allocator' and 'sso_storage' is what you would have to
implement.)
I would suggest also opening an feature request to Ion to allow providing a
mechanism to specify the alignment of the small_vector storage type.
Glen
-- View this message in context: http://boost.2283326.n4.nabble.com/small-vector-alignment-tp4692694p4692701.html Sent from the Boost - Dev mailing list archive at Nabble.com.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk