By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,654 Members | 936 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,654 IT Pros & Developers. It's quick & easy.

valarray or vector ?

P: n/a
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

Mar 22 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
toton wrote:
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
Mar 22 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.