Re: Equivalent of the gtk g_object_ref/unref functions in gtkmm?



On Thu, 2007-03-22 at 16:49 +0100, Jef Driesen wrote:
> When I look at some gtk C code, I see everywhere pointers to widgets 
> (and other things). As i understand all gtk objects are reference 
> counted to keep the objects alive until the last pointer is released.
> 
> How does that work in gtkmm? At first sight, gtkmm widgets doesn't seem 
> to be reference counted, because something like this does not work 
> (because of the private copy constructor):
> 
> Gtk::Button a, b(a);
> 
> Do I need to use smart pointers (e.g. boost::shared_ptr) for that? Does 
> that means the underlying gtk reference counting mechanism is not used 
> in gtkmm?

you're thinking much too hard. stop thinking, and just use the toolkit.

> I read in the gtkmm documentation there is a Glib::RefPtr, that uses the 
> internal gtk/gobject reference counting. If I understand that correctly, 
> I can use this smart pointer (instead of third party implementation like 
> boost)?
> 
> Glib::RefPtr<Gtk::Button> a(new Gtk::Button()), b(a);

nope, don't do this.

> But I've never seen that before, only with non-widgets objects like 
> pixbufs and treemodels.

correct.

> look like in gtkmm? Is a smart pointer going to interfere with the 
> automatic memory management when I add the widget to the notebook? Do I 
> need smart pointers at all for all this?

no, you don't smart pointers for anything directly related to GTKmm.
just create widgets. if they are on the heap (allocated via new
SomeWidget()), then wrap them with manage():

    Gtk::SomeWidget* foo = manage (new Gtk::SomeWidget())

if they are on the stack or members of objects, you don't even need to
do that.

--p



> 
> _______________________________________________
> gtkmm-list mailing list
> gtkmm-list gnome org
> http://mail.gnome.org/mailman/listinfo/gtkmm-list




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