Re: Subclassing in Gtk+ 3.0



On Tue, Dec 08, 2009 at 10:44:56AM -0500, A. Walton wrote:
> You can do something like a mix of 2, 3, and 4:
> * GSEAL() bridges the gap between 2.9x.x and 3.0 by making it easier
> to port and see where we're missing accessors.
> * Widgets are patched during the 3.0 ABI break so their currently
> public struct members are moved to GtkFooPrivate.
> * g_type_class_add_private() the GtkFooPrivate struct to prevent some
> fragmentation.
> * Add a GtkFooPrivate* to the object's public struct, populate it
> during gtk_foo_init() with
> a single G_TYPE_INSTANCE_GET_PRIVATE() call to speed up access and prevent
> duplicate GtkFooPrivate *priv = G_TYPE_INSTANCE_... lines.
> + roughly as fast as before, low memory overhead
> + code is future-proof and much easier to maintain with proper encapsulation
> - accessors are now mandatory, even for subclasses
> - code's a bit more ugly (when implementing a widget, 'widget->foo' is
> now 'widget->priv->foo').

Ah, that's clever, I didn't thought about `caching' of the private
pointer in the object struct, thanks.

Yeti



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