Tag Archives: performance

Improve performance: Use ->priv instead GET_PRIV() macros

Sure you already know this, but if someone don’t:

Maybe some of you have this in your *.c GObject files:

#define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), MY_TYPE_OBJECT, MyObjectPriv))

And then you use this macro in all your functions to access the GObject private structure.

You shouldn’t do this.

Instead, declare a *priv member in public structure and then access private members with my_object->priv->var

Maybe you think the performance improvement is not a lot. Well, I applied a similar patch to giggle [1] and now the startup time is ~10 second faster when opening the evolution git repository.

So, I think it’s worth 😉

Update: From Edward Hervey comments: Some of the benefits of use of G_TYPE_INSTANCE_GET_PRIVATE(): memory space gets allocated alongside your instance, avoids an extra alloc, memory is contiguous, …

[1] http://git.gnome.org/browse/giggle/commit/?id=72dbad7a4b0db2bed612d8666a640ae66082f936