Boost logo

Boost Users :

Subject: Re: [Boost-users] Object pools?
From: Ryan McConnehey (mccorywork_at_[hidden])
Date: 2010-02-18 11:08:00


michele.caini_at_[hidden] wrote:
> Hi, of course, in my opinion pool has to manage objects life time.
> However sharing objects with pool owner by shared ptr seems to be a
> good idea, because pool still manages objects life time.
You are correct, the objects given to the user are still controlled by
the pool but by passing the shared_ptr to the user the pool only has to
worry about those item in its direct control. The downside to passing
raw pointers to the user is the pool then has to keep track of which
objects it has passed to the user and which objects are still
available. This is an extra level detail that the shared_ptr allows us
to avoid.
> Using shared pointer also inside pool solves the problem, maybe. It is
> correct?
I wasn't able to use the shared_ptr inside the pool. When creating the
shared_ptr, the destructor function expects to call a function using the
raw pointer. So the pool stores raw pointers but passes them to the
user in a shared_ptr.

Ryan


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