Re: GObject get_property method copying string



Thank you very much for the help Emmanuele.

On Fri, Aug 19, 2011 at 3:13 PM, Emmanuele Bassi <ebassi gmail com> wrote:

On 2011-08-19 at 14:11, Tiago Katcipis wrote:


> I expected that the returned string would be the same as codec->payload, but
> on my tests, it is not, what i get when i call:
>
> gchar * payload = NULL;
>
> g_object_get (codec_info, "payload", &payload, NULL);

yes, this will always perform a copy of the string because of various
historical reasons and syntax limitations, especially when dealing with
transformable values; there is no actual way to know whether a property
will effectively make a copy of the string from outside the object
class.

if you use g_object_get_property() and a GValue* you should be able to
get the original pointer without a copy of the GValue payload — but
still at the cost of a couple of GValue boxing/copy/unboxing.

my recommendation, though, is to provide a function for direct access
and not go through g_object_set/_get; a direct accessors pair will allow
you to control the semantics of memory management instead of relying on
GObject's.

there is ongoing work to make GObject properties faster and more tied to
the private structures, e.g.:

 https://bugzilla.gnome.org/show_bug.cgi?id=648526

the bug above will introduce new API to declare and define properties
and relative accessors, and should also provide API to know the memory
management of the accessors as well; the code is available in the
g-property branch of GLib:

 http://git.gnome.org/browse/glib/log/?h=g-property

and testing is most welcome.

ciao,
 Emmanuele.

--
W: http://www.emmanuelebassi.name
B: http://blogs.gnome.org/ebassi
_______________________________________________
gnome-devel-list mailing list
gnome-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gnome-devel-list



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