cinitializationglibfinalization

GValue initialization/finalization necessity


When should I call g_value_init/g_value_reset?

Currently, I'm using g_value_init and g_value_reset in all cases, but I want to know whether it could be sped up.

I know at least that:

That's all my current research. I would like to broaden it, possibly backed by official documentation references. Thanks in advance.


Solution

  • Your current thoughts are mostly correct. g_value_init() must always be used to initialise a stack-allocated GValue. g_value_unset() must be used whenever a GValue goes out of scope, to release any type-specific data for it. g_value_reset() should be used if you want to reset a GValue to the default value — note that for some types this might mean it still points to allocated memory.

    g_value_unset() is typically used a lot more frequently than g_value_reset().