Boost logo

Boost :

Subject: Re: [boost] interest in structure of arrays container?
From: Larry Evans (cppljevans_at_[hidden])
Date: 2016-10-20 10:53:50


On 10/20/2016 03:55 AM, Larry Evans wrote:
> On 10/19/2016 11:59 PM, Michael Marcin wrote:
>> On 10/19/2016 7:32 AM, Larry Evans wrote:
>>>> Michael, the attached is an outline of how to do it.
>>>> As noted in the comments, a lot of member functions still need
>>>> implementation; however, the offset calculations I think are
>>>> correct.
>>>>
>>> Code has been updated to implement most of the "essentials" of
>>> soa_block. You can now call begin<Index> to get the begin
>>> iterator for the Index'th vector.
>>>
>>> The code now is on github at:
>>>
>>> https://github.com/cppljevans/soa/blob/master/soa_block.cpp
>>>
>>
>> Still digesting this
[snip]

> One change I made to the vec_offsets function could lead to
> a problem in some very special application. You might think
> that you could, instead of:
>
> , my_storage(new char[my_offsets.back()])
>
> in the soa_block CTOR initialization list, you wanted to
> create a vector of vectors, or matrx, of soa's. Then you
> might think you could:
>
> soa_impl(std::size_t a_row_size, std::size_t a_col_size)
> : my_row_size(a_row_size)
> , my_col_size(a_col_size)
> , my_offsets(vec_offsets<Ts...>(my_row_size))
> , my_storage(new char[my_offsets.back()*my_col_size])
> {
> ...
> }
>
> However, you couldn't because the 2nd column of the matrix
> *might* not have the correct alignment. That's because, I
> changed the vec_offsets function by replacing, in the
> vec_offsets function, this:
>
> result[sizeTs]=nxt_offset( result[sizeTs-1],
> sizes[sizeTs-1]*vec_size, max_align);
>
> with this:
>
> result[sizeTs]=result[sizeTs-1]+sizes[sizeTs-1]*vec_size;
>
> My justification for doing that was I assumed nobody would
> want to do that; however, who knows. Also, if I left in the
> original, and there was no need for it, then people
> reviewing the code would wonder why I put it in :(
>
> I'll try to find some comments to put in the vec_offsets
> function to warn people of this unlikely problem.

Running the just uploaded test file:

https://github.com/cppljevans/soa/blob/master/vec_offsets.test.cpp

produces,, for the last test, the output:

:vec_size=3:sizeof...(Ts)=2
sizeof...(Ts)=2
offset[0]=0
alignment[0]=16
aligned[0]=1
offset[1]=48
alignment[1]=4
aligned[1]=1
buf_size=84
max_alignment=16
max_aligned=0
   buf_size+offset[0]=84
   alignment[0]=16
   aligned[0]=0
   buf_size+offset[1]=132
   alignment[1]=4
   aligned[1]=1

Note the aligned[0]=0 line. This illustrates that when
2 buffers are concatenated, then the alignment for
the first T in the 2nd buffer will not be correct.

Hope that makes things clearer.

-regards,
Larry


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk