Boost logo

Boost Users :

From: James Swift (james_at_[hidden])
Date: 2006-06-06 12:02:37


Hi boost users,

I have a question regarding the best use of the boost pools and shared_ptr
Consider the following tree node object.

class A
{
public:
    typedef boost::shared_ptr< A > SPA;
    typedef std::vector< SPA > SPAVec;

    SPAVec children;
};

This class allows me to have a tree or trees where some of the nodes may
be shared. E.g.

// tree1 tree2
// X Z
// Y Y Y X
// Y Y

Logically the root of tree1, X has two children Y and Y but physically
of course I only have one copy of Y in memory. Other trees, e.g. tree2
can also share these branches.

Now assume I'm also very often constructing and destroying nodes. An
object pool is an obvious optimisation to try out. However shared_ptr
would need to call object_pool::destruct() instead of delete when it
really wants to destroy the object. Or singleton_pool::free() but this
causes more difficulties for me because I want to control the lifetime
of the pool separately for each instance of my objects which are working
on these trees.

Can anyone offer a nice solution to this problem?

kind regards,

James Swift.


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