g_object_data vs struct fields

Jasper Huijsmans jasper at xfce.org
Sun Jan 22 09:37:47 CET 2006


Jani Monoses schreef:
> Hello
> 
> looking at panel plugins, clock for example, I see that
> g_object_{set,get}_data() are used to store attributes of the plugin
> in this case dialog. Other plugins do this too, some for other fields as 
> well.
> 
> Why is this better than having a field in struct Clock as the dialog?
> For the actions and separator plugins I thought it is done because there 
> is no separate struct for the plugin, OTOH there is a quite large struct 
> Clock.
> 

Different ways to achieve the same thing. If you need a lot of data one 
struct to contain everything is more efficient than storing them 
separately as object data.

> It still is not clear to me what the exact difference of roles of the 
> plugin object and the optional plugin specific struct should be.
> They seem to be both able to be used for the same things with minor code 
> alterations as they both seem to be passed (or passable) to all functions.

Personally I would always use a separate struct (that must be allocated 
and freed by the plugin writer at the appropriate time), unless there is 
only one or two items to store.

> 
> Could the XfcePanelPlugin have another field besides 'child'? I see it's 
> a dummy class so I am not sure, but if it had an opaque pointer field 
> for each plugin's private use it would be less confusing.
> 

I had something like that initially, but I removed it, since it doesn't 
add any functionality that is not otherwise available. So, a plugin 
writer can basically do whatever he prefers ;-)

	Jasper



More information about the Xfce4-dev mailing list