Boost logo

Boost Users :

From: Thorsten Ottosen (thorsten.ottosen_at_[hidden])
Date: 2008-03-05 03:13:50


j.c. skrev:
> Hi,
> I have an pointer array of objects as follows:
>
> bucket * m_buckets[BUCKET_SIZE];
>
> Because this array is a set size does it make sense to use
> a boost::ptr_array?
>
> boost::ptr_array<bucket, BUCKET_SIZE> m_buckets;
>
> * Note: One thing I first noticed with boost::array is that I cannot
> perform operations such as inserting at a desired index:
>
> // Existing code.
> m_buckets[bit] = new bucket(k,v);
>
> My goal is to use as many smart pointers as I can and less heap allocation.

   m_buckets.replace<bit>( new bucket(k,v) );

or

   m_buckets.replace( bit, new bucket(k.v) );

should work for boost::ptr_array<T,N> dependending on whether "bit" is
known at compile time.

-Thorsten


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