Re: g_intern_static_string() for type names as small optimization
- From: "Andrew W. Nosenko" <andrew w nosenko gmail com>
- To: Ross Burton <ross burtonini com>
- Cc: gtk-devel-list gnome org
- Subject: Re: g_intern_static_string() for type names as small optimization
- Date: Wed, 16 Jan 2008 18:24:11 +0200
On Jan 16, 2008 5:06 PM, Ross Burton <ross burtonini com> wrote:
> On Wed, 2008-01-16 at 16:53 +0200, Andrew W. Nosenko wrote:
> > Matthias (or anyone else), could you explain, what this "small
> > optimization" optimizes (what use-cases, on what way, etc), why and
> > how big win/profit gives?
>
> As the documentation says:
>
> "g_intern_static_string() does not copy the string, therefore string
> must not be freed or modified."
>
> When you are talking about several strings for every object, not having
> to copy every one saves both time and memory.
Sorry, seems my wording was not clear enough...
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?
--
Andrew W. Nosenko <andrew w nosenko gmail com>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]