On Sun, 18 May 2008 12:04:12 +0100
Emmanuele Bassi <[EMAIL PROTECTED]> wrote:

> On Sun, 2008-05-18 at 12:54 +0200, Nicola Fontana wrote:
> > struct _MyInstance
> > {
> >   MyParent *parent;
> > };
> 
> no, it will be:
> 
>   struct _MyInstance
>   {
>     MyParent parent_instance;
>   };

You're right. Just to see if you notice it...

> > for every object, and this sounds me quite weird.
> 
> why?

Well, it was stinking as a useless struct.

> > Is this a common approach?
> 
> yes, if you plan to only have accessor functions. you might provide
> structure members, but that will make it difficult to change them, in
> case you plan to restructure your API.
> 
> > Is there an official/preferred/best way to do this?
> 
> you can also have a:
> 
>   MyInstancePrivate *priv;
> 
> pointer, to avoid the calls to G_TYPE_INSTANCE_GET_PRIVATE() every time
> you need to access the private data.

Do you mean to assign G_TYPE_INSTANCE_GET_PRIVATE() to priv
after the object instantiation? This is a good idea.

The GObject tutorial, if I caught it well, uses priv as a
pointer you must alloc/dealloc by hand, and this will add a new
malloc on every instantiation... not so good, but maybe this is
the old school.

> remember: the instance structure should be as opaque as possible.
> 
> ciao,
>  Emmanuele.
> 
> -- 
> Emmanuele Bassi,
> W: http://www.emmanuelebassi.net
> B: http://log.emmanuelebassi.net

Thank you for your feedback: this was exactly what I was looking
for.

Ciao
-- 
Nicola
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Reply via email to