|
Boost Users : |
From: Lorenzo Bolla (bolla_at_[hidden])
Date: 2004-06-15 02:38:25
have you had a look at the boost::numeric::ublas::vector?
you can specify a "storage" class to keep the data (for example a simple
pointer to raw memory allocated with "new []") and it keeps a "size_"
internal variable (to improve performance, I suppose).
check:
boost/numeric/ublas/vector.hpp for class vector
boost/numeric/ublas/storage.hpp for class unbounded_array
hope this helps.
lorenzo.
On Tue, Jun 15, 2004 at 01:11:05AM -0500, Bo Peng wrote:
> On Mon, Jun 14, 2004 at 10:51:12PM -0700, Victor A. Wagner Jr. wrote:
> > that's the answer on YOUR implementation...do NOT make assumptions about
> > how all are implemented.
>
> I am aware of this. The implementation I checked is for gcc 3.2.2.
> However, there has to be some overheads (several pointers at least) in
> any vector implementation. Something between boost::array and
> std::vector can be useful.
>
> What is in my mind is a version of boost::array that can has 0 or a
> fixed length. It might look like:
>
> template<class T>
> class carray {
> public:
> size_t N;
> // if carray is created by carray(n,elem), do not have ownership to elems.
> T* elems;
> // constructor
> carray():N(0),elems(NULL){}
>
> // create array
> carray(size_t size):N(size){
> elems = new T[size];
> }
> // destructor
> ~carray(){
> if(elems!=NULL) delete[] elems;
> }
> // copy constructor,
> // can copy from carray, boost::array or vector
> ...
> // maybe some constructors as those in vector (vec(ptr1, ptr2))
> // or things like carray(int n, T* t) to assemble carray
> // from existing array t without copying things...
> ...
> // resize, can be called only when N=0.
> resize(int n){ .... }
>
> // iterators and everything else can be copied directly
> // from boost::array.
>
> }
>
> Bo
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- CH3 | N / \ N----C C==O || || | || || | CH C N--CH3 \ / \ / N C | || CH3 O
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net