Re: Glib::RefPtr vs boost::shared_ptr



On 6/26/06, Joe Van Dyk <joevandyk gmail com> wrote:
How does Glib::RefPtr compare to boost::shared_ptr?

Thanks,
Joe
_______________________________________________
gtkmm-list mailing list
gtkmm-list gnome org
http://mail.gnome.org/mailman/listinfo/gtkmm-list



Glib::RefPtr is not really a general-purpose smart pointer like
boost::shared_ptr.  Glib::RefPtr requires that the object it points to
keep track of the reference.  This is good for wrapping GLib/GTK+
objects because reference-counted GObject types already have their own
reference count, so adding a reference count in the smart pointer
would just be duplication and introduce the possibility that the two
counts could be out of sync.  On the other hand, this same property
means that it's not ideal for use with general types since you'd have
to manage the reference-counting manually for each different type you
wanted to use it with.

So in general, if you want a smart pointer of an object isn't designed
to work with Glib::RefPtr, you'd be better off using a general-purpose
smart pointer like boost::shared_ptr in your application code.

Does that help?

Jonner



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]