Re: g_intern_static_string() for type names as small optimization
- From: "Andrew W. Nosenko" <andrew w nosenko gmail com>
- To: "Matthias Clasen" <matthias clasen gmail com>
- Cc: gtk-devel-list gnome org, Ross Burton <ross burtonini com>
- Subject: Re: g_intern_static_string() for type names as small optimization
- Date: Wed, 16 Jan 2008 19:59:25 +0200
On Jan 16, 2008 7:43 PM, Matthias Clasen <matthias clasen gmail com> wrote:
> On Jan 16, 2008 11:24 AM, Andrew W. Nosenko <andrew w nosenko gmail com> wrote:
>
> >
> > I'm asking not about general benefits of an intern strings or GQuarks
> > (which are backend of Glib's intern strings), but about benefits, which
> > expected by GTK/Glib developers, for constructs like (please, pay
> > attention on the 2nd parameter of the g_type_register_static())
> >
> > type_module_type = g_type_register_static (G_TYPE_OBJECT,
> > g_intern_static_string ("GTypeModule"),
> > /* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */
> > &type_module_info,
> > G_TYPE_FLAG_ABSTRACT);
> >
> > in comparison with using of the "plain" 'const char*' string in the same
> > context:
> >
> > type_module_type = g_type_register_static (G_TYPE_OBJECT,
> > "GTypeModule",
> > /* ^^^^^^^^^^ */
> > &type_module_info,
> > G_TYPE_FLAG_ABSTRACT);
> >
> > because underlying machinery of the g_type_register_static() cannot
> > assume that 'type_name' parameter is interned and, therefore, either
> > should use strcmp() all the times (don't belive, but...), or (more
> > probable) just to convert it to GQuark or intern string again by self.
> >
> > Therefore a question: what win/profit/optimization gives this early
> > interning?
> >
>
> The thing is that GObject interns the type name anyway. But, as you say,
> it cannot assume that the string is static and thus calls g_intern_string(),
> causing it to be copied. By interning it using
> g_intern_static_string() beforehand,
> we guarantee that the string is already interned at the time that gobject calls
> g_intern_string, and thus won't be copied.
>
> As I said, it is a pretty small optimization...
Thanks! It's a pretty clear answer!
--
Andrew W. Nosenko <andrew w nosenko gmail com>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]