Boost logo

Boost :

From: Olivier Grant (olivier.grant_at_[hidden])
Date: 2006-09-22 09:57:09


Well due to the fact that floats are represented on 4 bytes, there shouldn't
be any padding involved. Padding normally occures when certain member
variables of a structure require certain alignment constraints or just for
efficiency, but this shouldn't occur with a vector class (at least that is
my understanding).

It is the same thing with alignment. the beginning of the structure is
placed on a certain boundary but doesn't affect the padding of elements
within the structure. You could set this vector class to be 16 bytes aligned
if you wanted to use them with SSE instructions, and you can still access
the member with the array operator without problems.

Olivier.

On 9/22/06, Sohail Somani <s.somani_at_[hidden]> wrote:
>
> Won't that not work in the presence of padding? Sorry for the TP, lookout
> webmail.
>
> -----Original Message-----
> From: boost-bounces_at_[hidden] on behalf of Marcus Lindblom
> Sent: Fri 9/22/2006 12:17 AM
> To: boost_at_[hidden]
> Subject: Re: [boost] Geometry/Vector Lib
>
> Olivier Grant wrote:
> > I agree on your point, on the other hand, you can do this :
> >
> > class vector3d
> > {
> > public:
> > float x, y, z;
> >
> > float operator[]( int index ) const
> > { return ((float *)this)[index]; }
> >
> > float & operator[]( int index )
> > { return ((float *)this)[index]; }
> >
> > /* ... */
> > };
> >
> > in which case "v.x" and "v[0]" are the same thing. this is what I
> currently
> > have. Now some people will argument its a hack maybe.
> >
> I've sometimes done just:
>
> class vector3d
> {
> public:
> float x, y, z;
>
> float operator[]( int index ) const
> { return (&x)[index]; }
>
> /* ... */
> };
>
> /Marcus
> _______________________________________________
> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost
>


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