|
Boost : |
From: Bradford, Chase (CHASE.BRADFORD_at_[hidden])
Date: 2008-07-24 17:18:22
> -----Original Message-----
> From: boost-bounces_at_[hidden]
[mailto:boost-bounces_at_[hidden]]
> On Behalf Of Mathias Gaunard
> Sent: Thursday, July 24, 2008 2:03 PM
> To: boost_at_[hidden]
> Subject: Re: [boost] generict container for structure of arrays
>
> Bradford, Chase wrote:
>
> > int main()
> > {
> > typedef basic_soa<std::string, boost::variant<int, float> > MySoa;
> >
> > MySoa s;
> >
> > // Make internal vectors hold 100 elements.
> > s.resize(100);
> >
> > // Create a fields named x and y. This sort of makes the object a
> > // container of 2D points.
> > s.add_field<float>("x");
> > s.add_field<float>("y");
> >
> > fill( s.field<float>("x").begin(), s.field<float>("x").end(),
rand);
> > fill( s.field<float>("y").begin(), s.field<float>("y").end(),
rand);
>
> If I understand your example correctly, it's quite similar to a
> std::(unordered_)map<Key, std::vector<Value> >.
>
In many ways they are similar except:
1) All map value types are vector<T>. In the example, the underlying
types can simultaneously be vector<int> or vector<float>, since its
driven by a variant.
2) A map of key, vector pairs cannot ensure that all vectors are
identical in length.
3) Map doesn't provide any mechanism for viewing slices of the data.
The main purpose of this container is to store data in a
structure-of-arrays layout, instead of an array-of-structures. A quick
comparison of the two approaches can be found here:
hectorgon.blogspot.com/2006/08/array-of-structures-vs-structure-of.html
Chase
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk