Boost logo

Ublas :

Subject: Re: [ublas] fixed size vector in boost::numeric::ublas?
From: Nasos Iliopoulos (nasos_i_at_[hidden])
Date: 2010-07-23 08:43:56


Marko,

The c_vector indeed works on the stack, but it still has a redundant size member function, that when used small fixed containers (i.e. 2 element vectors), causes some serious memory overhead.

Furthermore getting rid of the size member variable opens a nice opportunity to cast items from and to a fixed_vector (or matrix) for a variety of nice interfacing tricks.

For example consider the following:

std::vector<ublas::fixed_vector<float,3> > vertices;

the following statement:

 static_cast<float *>(&vertices[0])

will return a pointer that can go directly to say OpenGL to create a vertex buffer, while at the same time retain all the uBlas stuff to operate on your vertices! (as long as you don't want to go the shader way and you can afford to update the vertices every frame - a common scenario when you morph them).
 
Very Best,
Nasos

> Date: Fri, 23 Jul 2010 10:20:43 +0200
> From: marco.guazzone_at_[hidden]
> To: ublas_at_[hidden]
> Subject: Re: [ublas] fixed size vector in boost::numeric::ublas?
>
> On Fri, Jul 23, 2010 at 10:03 AM, Andrea Cassioli
> <cassioliandre_at_[hidden]> wrote:
> > Hi guys,
> > I've played a little bit with the fixed_size array (which was missing
> > as far as I know in uBlas) and seems to be a very promising idea!
> > Looking around to address the issues you rise about the fixed_array
> > ctor, array items initialization does not seem an easy to solve
> > problem.
> > Some people propose to use #define expansion to recursively generate a
> > list of the type
> >
> > array_type v[N]={value,value..}
> >
> > But personally I do not think it is a crucial issues at the present time.
> >
> > Good job guys!
>
> Hi,
>
> Does the ublas::c_vector class already implement this kind of vectors?
>
> As you can see from its definition:
>
> template<class T, std::size_t N>
> class c_vector;
>
> You bind the size at compile time, and indeed the internal container
> can be implemented as a static (i.e. on the stack) array.
>
> Cheers,
>
> -- Marco
> _______________________________________________
> ublas mailing list
> ublas_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/ublas
> Sent to: nasos_i_at_[hidden]
                                               
_________________________________________________________________
The New Busy is not the too busy. Combine all your e-mail accounts with Hotmail.
http://www.windowslive.com/campaign/thenewbusy?tile=multiaccount&ocid=PID28326::T:WLMTAGL:ON:WL:en-US:WM_HMP:042010_4