Boost logo

Boost Users :

From: Joseph Thomson (joseph.thomson_at_[hidden])
Date: 2008-04-07 11:31:56


Actually, I think I have a better way which uses auto_ptr (or the boost ptr
containers) as you suggested. It still isn't thread safe, but this isn't of
immediate concern, and there are other methods for this anyway.

Before, I was storing a map of shared_ptrs in the ObjectManager and a
weak_ptr reference in any ObjectHandles to check if the object is still
valid. Instead:

- A map of auto_ptrs (or a ptr_map of Objects) would be stored in the
ObjectManager.
- On its creation, Object would create and store a shared_ptr<ObjectHandle>,
passing a raw pointer to it in the process (don't worry, this is still
safe).
- Any user wanting to get access to the Object would request an ObjectHandle
from ObjectManager, which would in turn request a copy of Object's
shared_ptr<ObjectHandle>.
- On its destruction (by ObjectManager), Object would inform its
ObjectHandle of its destruction, and ObjectHandle would set an internal flag
to indicate that it is expired.
- ObjectHandle would handle any requests from the user by first checking the
expiry flag, and then forwarding the call to Object using its stored raw
pointer. The expiry flag is set by the Object itself, so there is no chance
of the pointer being invalid when called.

Any advice/thoughts are appreciated.

Cheers,

Joe

-- 
View this message in context: http://www.nabble.com/-smart_ptr--Sole-ownership-of-shared_ptr--tp16528658p16537507.html
Sent from the Boost - Users mailing list archive at Nabble.com.

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