Boost logo

Boost Users :

From: voodoo4 (voodoo4_at_[hidden])
Date: 2004-02-26 05:41:28


*Cyril Godart wrote:*
> Hi,
>
> I suggest the following code:
>
> class Master
> {
> typedef boost::smart_ptr<Slave> slave_ptr_t;
> typedef boost::smart_ptr<const Slave> slave_cst_ptr_t;
>
> typedef std::vector<slave_ptr_t> vec_slaves_t;
> typedef std::vector<slave_cst_ptr_t> vec_cst_slaves_t;//defining
this
> one is good practice as you'll see later
>
> Master();
> Master(size_t i)
> {
> slaves_.resize(i);// assume slave has an empty ctor defined.
> }
>
> vec_cst_slaves_t slaves() //something like const vec_cst_slaves_t&
> slaves() const should work
> {
> return slaves_; //nice casting that I failed to notice until
> someone in this list mentioned it to me
> };
>
> vec_slaves_t slaves_;
> };
>
> As you rightly guessed, a big advantage of this approach is that the
> plumbing of copy-assigment
> dtor and so on reduces drastically. I find it extremely convenient, even
> though there is a performance
> hit.

It would be a good choice to use vectors instead of arrays but since my
project is
a game i'm interested in performance penalties.(smart pointers will be used
for memory management)
I guess i can benchmark both ways and make my choice but i can't do that
before making the arrays work the way i want.


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