Re: [gtkmm] using RefPtr out of Gtkmm
- From: Murray Cumming <murrayc murrayc com>
- To: Chris Vine <chris cvine freeserve co uk>
- Cc: Paul Elliott <pelliott io com>, gtkmm-list <gtkmm-list gnome org>, Jose Felix Hernandez Barrio <jfhernandez etsii upm es>
- Subject: Re: [gtkmm] using RefPtr out of Gtkmm
- Date: Fri, 13 Feb 2004 20:16:28 +0100
On Thu, 2004-02-12 at 00:44, Chris Vine wrote:
> On Wednesday 11 February 2004 22:32, Paul Elliott wrote:
> > On the other hand, there is a logic to intrusive reference counting
> > where there is inheritance. Suppose Derived is derived from Base,
> > and EvenMoreDerived is derived from Derived. Suppose my_instance
> > is a instance of EvenMoreDerived. Different modules "think"
> > of my_instance in deferent ways. Module A deals with my_instance
> > as a Base and wants to keep a smart pointer to base of my_instance.
> > Module C deals with my_instance as a Derived and wants to keep
> > a smart pointer to my_instance as a Derived. Module C deals with
> > my_instance as an EvenMoreDerived ect.
> > How would you do that with unintrusive pointers? smart_ptr<Base>,
> > smart_ptr<Derived>, smart_ptr<EvenMoreDerived> how do they
> > all use a common reference count?
> > With intrusive reference counts, the refcounts can be hidden
> > in the Object class that all these other classes have to be dervied from.
> > With unintrusive reference counts the templade smart_ptr<EvenMoreDerived>
> > does not even know that Base and Derived exist, so how can it
> > use the same reference counts as these?
> By using template member functions in the smart pointer, and using
> smart_ptr<Base> to reference the class heirarchy. Any competently written
> constructors for a smart pointer will include a templated constructor, so
> allowing a base smart pointer to be initialised by a derived object by
> implicit conversion (and also a templated operator=() function for the same
> reason). If the base class has a virtual destructor (as it should), then all
> will work correctly.
Yes, RefPtr and all my other smartpointers do casting like this too. The
only reason I ever had to use an intrusive smartpointer was
- RefPtr and gtkmm memory management is to easier implement that way
(but we have a glibmm patch that makes it mostly non-intrusive.)
- A compiler could not do the templated methods of templated classes, so
the underlying instance had to be taken out of the smartpointer
sometimes to cast it, so the refcount had to be in the instance rather
than the smartpointer.
murrayc murrayc com
] [Thread Prev