valarray or vector ?

T

toton

Hi,
I am using vector and similar containers extensively for my project,
as well as boost circular_buffer_space_optimized (and adobe
circular_queue which is built over vector ). They all work with
iterator based concept.
As I need to refer a portion of the vector (or circular buffer )
from within a class , I need to store index (not iterators, as
container elements are movable ) or a pair of index within the class
(using std::distance to get index from iterator, all of my containers
are random access ). now from index , I create boost sub_range and use
it.
For arbitrary access, I store a vector<size_t>, and use boost
permutation_iterator with the index.
One point here, iterator is not very cheap when it is circular_buffer
(and space optimized version) , as it is not merely a pointer , and it
need to know container (i.e. store a ref to container) or store 3
pointers, one current pos, one for begin of buffer, one end of buffer
(boost uses former version).

But after that I came to a different concept , a concept of view,
which is used by boost uBLAS containers Blitz array and the STL low
profile container valarray. Now it seems slice_view , range_view are
cheaper for circular buffer, as only one reference to container is
stored (esp when using permutation_iterator or arbitrary sequence
access). Also seems cross referencing from one valarray to another is
easier due to slice concept which can be directly stored. and it also
provides some numeric operations.
In my case all of the arrays are one dimensional, and they are array
of some small struct (like point, tangent etc) most of them have some
geometric meaning. And mostly I want to have some numeric operations
on them (my original test implementation is in matlab and the array in
matlab is just like Blitz array with little more overhead)
I am little confused at this stage, which one to use. and if I use
valarray kind of thing , how to use stl algorithm's with it (i.e how
to get a iterator from it ? valarray is continuous so getting iterator
is not a problem, but not sure whether I can sort a slice) .

Can anyone help in this regard?

abir
 
F

Fei Liu

toton said:
Hi,
I am using vector and similar containers extensively for my project,
as well as boost circular_buffer_space_optimized (and adobe
circular_queue which is built over vector ). They all work with
iterator based concept.
As I need to refer a portion of the vector (or circular buffer )
from within a class , I need to store index (not iterators, as
container elements are movable ) or a pair of index within the class
(using std::distance to get index from iterator, all of my containers
are random access ). now from index , I create boost sub_range and use
it.
For arbitrary access, I store a vector<size_t>, and use boost
permutation_iterator with the index.
One point here, iterator is not very cheap when it is circular_buffer
(and space optimized version) , as it is not merely a pointer , and it
need to know container (i.e. store a ref to container) or store 3
pointers, one current pos, one for begin of buffer, one end of buffer
(boost uses former version).

But after that I came to a different concept , a concept of view,
which is used by boost uBLAS containers Blitz array and the STL low
profile container valarray. Now it seems slice_view , range_view are
cheaper for circular buffer, as only one reference to container is
stored (esp when using permutation_iterator or arbitrary sequence
access). Also seems cross referencing from one valarray to another is
easier due to slice concept which can be directly stored. and it also
provides some numeric operations.
In my case all of the arrays are one dimensional, and they are array
of some small struct (like point, tangent etc) most of them have some
geometric meaning. And mostly I want to have some numeric operations
on them (my original test implementation is in matlab and the array in
matlab is just like Blitz array with little more overhead)
I am little confused at this stage, which one to use. and if I use
valarray kind of thing , how to use stl algorithm's with it (i.e how
to get a iterator from it ? valarray is continuous so getting iterator
is not a problem, but not sure whether I can sort a slice) .

Can anyone help in this regard?

abir
Since they are all one dimensional, I would recommend using vector.

Fei
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top