Re: g_value_new Macro?



On Thu, 2004-08-26 at 09:22, ext Ryan McDougall wrote:
> Hi,
> 
> I use the following in my code. Is there a reason why its not in the
> GValue API? Is it evil? If not, wouldn't it be nice to include it?
> 
> #define	g_value_new(type)	g_value_init (g_new (GValue, 1), type)

I think it's because you don't generally need to allocate GValues
dynamically.  Rather, you do:

GValue value = { 0 };
g_value_init (&value, G_TYPE_FOO);
...
g_value_unset (&value);


The last part is actually quite important that you missed in the
tutorial.  If your GValue holds a string or an object, failing to unset
the value is likely to leak memory.

The same thing happens if you don't g_free() or g_object_unref() things
you get from g_object_get()


-- 
Tommi Komulainen                              tommi komulainen nokia com



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