[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]
Re: whats the purpose of quark
- From: Emmanuele Bassi <ebassi gmail com>
- To: gtk-app-devel-list gnome org
- Subject: Re: whats the purpose of quark
- Date: Thu, 24 Jan 2008 07:55:14 +0000
On Thu, 2008-01-24 at 11:40 +0800, Binary Chen wrote:
> > > In glib there is a primitive named quark, it relates a ID with a
> > > string, but whats the advantage for this? Can we use a string instead,
> > > just to save some bytes for duplicated strings?
> >
> > It has the same advantages as string interning in any other
> > language...
>
> Can you give me an example for this?
static GQuark foo_quark = 0;
static const gchar *foo_str =
"a-very-long-string-to-compare-many-times";
foo_quark = g_quark_from_static_string (foo_str);
quark = g_quark_try_string (some_str);
if (quark == foo_quark)
g_print ("'%s' matches '%s'\n", some_str, foo_str);
this could also be done using g_intern_static_string() and
g_intern_string(), and then comparing the pointers.
ciao,
Emmanuele.
--
Emmanuele Bassi,
W: http://www.emmanuelebassi.net
B: http://log.emmanuelebassi.net
[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]