1
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
4
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
6
<meta name="generator" content="DocBook XSL Stylesheets V1.72.0">
7
<link rel="start" href="index.html" title="GLib Reference Manual">
8
<link rel="up" href="glib-data-types.html" title="GLib Data Types">
9
<link rel="prev" href="glib-N-ary-Trees.html" title="N-ary Trees">
10
<link rel="next" href="glib-Keyed-Data-Lists.html" title="Keyed Data Lists">
11
<meta name="generator" content="GTK-Doc V1.7 (XML mode)">
12
<link rel="stylesheet" href="style.css" type="text/css">
13
<link rel="chapter" href="glib.html" title="GLib Overview">
14
<link rel="chapter" href="glib-fundamentals.html" title="GLib Fundamentals">
15
<link rel="chapter" href="glib-core.html" title="GLib Core Application Support">
16
<link rel="chapter" href="glib-utilities.html" title="GLib Utilities">
17
<link rel="chapter" href="glib-data-types.html" title="GLib Data Types">
18
<link rel="chapter" href="tools.html" title="GLib Tools">
19
<link rel="index" href="ix01.html" title="Index">
20
<link rel="index" href="ix02.html" title="Index of deprecated symbols">
21
<link rel="index" href="ix03.html" title="Index of new symbols in 2.2">
22
<link rel="index" href="ix04.html" title="Index of new symbols in 2.4">
23
<link rel="index" href="ix05.html" title="Index of new symbols in 2.6">
24
<link rel="index" href="ix06.html" title="Index of new symbols in 2.8">
25
<link rel="index" href="ix07.html" title="Index of new symbols in 2.10">
26
<link rel="index" href="ix08.html" title="Index of new symbols in 2.12">
28
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
29
<table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2">
31
<td><a accesskey="p" href="glib-N-ary-Trees.html"><img src="left.png" width="24" height="24" border="0" alt="Prev"></a></td>
32
<td><a accesskey="u" href="glib-data-types.html"><img src="up.png" width="24" height="24" border="0" alt="Up"></a></td>
33
<td><a accesskey="h" href="index.html"><img src="home.png" width="24" height="24" border="0" alt="Home"></a></td>
34
<th width="100%" align="center">GLib Reference Manual</th>
35
<td><a accesskey="n" href="glib-Keyed-Data-Lists.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td>
37
<tr><td colspan="5" class="shortcuts"><nobr><a href="#id3137609" class="shortcut">Top</a>
39
<a href="#id3137766" class="shortcut">Description</a></nobr></td></tr>
41
<div class="refentry" lang="en">
42
<a name="glib-Quarks"></a><div class="titlepage"></div>
43
<div class="refnamediv"><table width="100%"><tr>
46
<a name="id3137609"></a><span class="refentrytitle">Quarks</span>
48
<p>Quarks — a 2-way association between a string and a unique integer identifier.</p>
50
<td valign="top" align="right"></td>
52
<div class="refsynopsisdiv">
54
<pre class="synopsis">
56
#include <glib.h>
59
typedef <a href="glib-Quarks.html#GQuark">GQuark</a>;
60
<a href="glib-Quarks.html#GQuark">GQuark</a> <a href="glib-Quarks.html#g-quark-from-string">g_quark_from_string</a> (const <a href="glib-Basic-Types.html#gchar">gchar</a> *string);
61
<a href="glib-Quarks.html#GQuark">GQuark</a> <a href="glib-Quarks.html#g-quark-from-static-string">g_quark_from_static_string</a> (const <a href="glib-Basic-Types.html#gchar">gchar</a> *string);
62
const <a href="glib-Basic-Types.html#gchar">gchar</a>* <a href="glib-Quarks.html#g-quark-to-string">g_quark_to_string</a> (<a href="glib-Quarks.html#GQuark">GQuark</a> quark);
63
<a href="glib-Quarks.html#GQuark">GQuark</a> <a href="glib-Quarks.html#g-quark-try-string">g_quark_try_string</a> (const <a href="glib-Basic-Types.html#gchar">gchar</a> *string);
64
const <a href="glib-Basic-Types.html#gchar">gchar</a>* <a href="glib-Quarks.html#g-intern-string">g_intern_string</a> (const <a href="glib-Basic-Types.html#gchar">gchar</a> *string);
65
const <a href="glib-Basic-Types.html#gchar">gchar</a>* <a href="glib-Quarks.html#g-intern-static-string">g_intern_static_string</a> (const <a href="glib-Basic-Types.html#gchar">gchar</a> *string);
68
<div class="refsect1" lang="en">
69
<a name="id3137766"></a><h2>Description</h2>
71
Quarks are associations between strings and integer identifiers.
72
Given either the string or the <a href="glib-Quarks.html#GQuark"><span class="type">GQuark</span></a> identifier it is possible to
76
Quarks are used for both
81
To create a new quark from a string, use <a href="glib-Quarks.html#g-quark-from-string"><code class="function">g_quark_from_string()</code></a> or
82
<a href="glib-Quarks.html#g-quark-from-static-string"><code class="function">g_quark_from_static_string()</code></a>.
85
To find the string corresponding to a given <a href="glib-Quarks.html#GQuark"><span class="type">GQuark</span></a>, use <a href="glib-Quarks.html#g-quark-to-string"><code class="function">g_quark_to_string()</code></a>.
88
To find the <a href="glib-Quarks.html#GQuark"><span class="type">GQuark</span></a> corresponding to a given string, use <a href="glib-Quarks.html#g-quark-try-string"><code class="function">g_quark_try_string()</code></a>.
91
Another use for the string pool maintained for the quark functions is string
92
interning, using <a href="glib-Quarks.html#g-intern-string"><code class="function">g_intern_string()</code></a> or <a href="glib-Quarks.html#g-intern-static-string"><code class="function">g_intern_static_string()</code></a>. An interned string
93
is a canonical representation for a string. One important advantage of interned strings
94
is that they can be compared for equality by a simple pointer comparision, rather than
95
using <code class="function">strcmp()</code>.
98
<div class="refsect1" lang="en">
99
<a name="id3137922"></a><h2>Details</h2>
100
<div class="refsect2" lang="en">
101
<a name="id3137932"></a><h3>
102
<a name="GQuark"></a>GQuark</h3>
103
<a class="indexterm" name="id3137944"></a><pre class="programlisting">typedef guint32 GQuark;
106
A GQuark is an integer which uniquely identifies a particular string.
110
<div class="refsect2" lang="en">
111
<a name="id3137961"></a><h3>
112
<a name="g-quark-from-string"></a>g_quark_from_string ()</h3>
113
<a class="indexterm" name="id3137974"></a><pre class="programlisting"><a href="glib-Quarks.html#GQuark">GQuark</a> g_quark_from_string (const <a href="glib-Basic-Types.html#gchar">gchar</a> *string);</pre>
115
Gets the <a href="glib-Quarks.html#GQuark"><span class="type">GQuark</span></a> identifying the given string.
116
If the string does not currently have an associated <a href="glib-Quarks.html#GQuark"><span class="type">GQuark</span></a>, a new
117
<a href="glib-Quarks.html#GQuark"><span class="type">GQuark</span></a> is created, using a copy of the string.
119
<div class="variablelist"><table border="0">
120
<col align="left" valign="top">
123
<td><span class="term"><em class="parameter"><code>string</code></em> :</span></td>
128
<td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td>
129
<td>the <a href="glib-Quarks.html#GQuark"><span class="type">GQuark</span></a> identifying the string.
138
<div class="refsect2" lang="en">
139
<a name="id3138064"></a><h3>
140
<a name="g-quark-from-static-string"></a>g_quark_from_static_string ()</h3>
141
<a class="indexterm" name="id3138078"></a><pre class="programlisting"><a href="glib-Quarks.html#GQuark">GQuark</a> g_quark_from_static_string (const <a href="glib-Basic-Types.html#gchar">gchar</a> *string);</pre>
143
Gets the <a href="glib-Quarks.html#GQuark"><span class="type">GQuark</span></a> identifying the given (static) string.
144
If the string does not currently have an associated <a href="glib-Quarks.html#GQuark"><span class="type">GQuark</span></a>, a new
145
<a href="glib-Quarks.html#GQuark"><span class="type">GQuark</span></a> is created, linked to the given string.
148
Note that this function is identical to <a href="glib-Quarks.html#g-quark-from-string"><code class="function">g_quark_from_string()</code></a> except
149
that if a new <a href="glib-Quarks.html#GQuark"><span class="type">GQuark</span></a> is created the string itself is used rather than
150
a copy. This saves memory, but can only be used if the string will
151
<span class="emphasis"><em>always</em></span> exist. It can be used with statically
152
allocated strings in the main program, but not with statically
153
allocated memory in dynamically loaded modules, if you expect to
154
ever unload the module again (e.g. do not use this function in
157
<div class="variablelist"><table border="0">
158
<col align="left" valign="top">
161
<td><span class="term"><em class="parameter"><code>string</code></em> :</span></td>
166
<td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td>
167
<td>the <a href="glib-Quarks.html#GQuark"><span class="type">GQuark</span></a> identifying the string.
176
<div class="refsect2" lang="en">
177
<a name="id3138202"></a><h3>
178
<a name="g-quark-to-string"></a>g_quark_to_string ()</h3>
179
<a class="indexterm" name="id3138214"></a><pre class="programlisting">const <a href="glib-Basic-Types.html#gchar">gchar</a>* g_quark_to_string (<a href="glib-Quarks.html#GQuark">GQuark</a> quark);</pre>
181
Gets the string associated with the given <a href="glib-Quarks.html#GQuark"><span class="type">GQuark</span></a>.
183
<div class="variablelist"><table border="0">
184
<col align="left" valign="top">
187
<td><span class="term"><em class="parameter"><code>quark</code></em> :</span></td>
188
<td>a <a href="glib-Quarks.html#GQuark"><span class="type">GQuark</span></a>.
192
<td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td>
193
<td>the string associated with the <a href="glib-Quarks.html#GQuark"><span class="type">GQuark</span></a>.
202
<div class="refsect2" lang="en">
203
<a name="id3138296"></a><h3>
204
<a name="g-quark-try-string"></a>g_quark_try_string ()</h3>
205
<a class="indexterm" name="id3138310"></a><pre class="programlisting"><a href="glib-Quarks.html#GQuark">GQuark</a> g_quark_try_string (const <a href="glib-Basic-Types.html#gchar">gchar</a> *string);</pre>
207
Gets the <a href="glib-Quarks.html#GQuark"><span class="type">GQuark</span></a> associated with the given string, or 0 if the string has
208
no associated <a href="glib-Quarks.html#GQuark"><span class="type">GQuark</span></a>.
211
If you want the GQuark to be created if it doesn't already exist, use
212
<a href="glib-Quarks.html#g-quark-from-string"><code class="function">g_quark_from_string()</code></a> or <a href="glib-Quarks.html#g-quark-from-static-string"><code class="function">g_quark_from_static_string()</code></a>.
214
<div class="variablelist"><table border="0">
215
<col align="left" valign="top">
218
<td><span class="term"><em class="parameter"><code>string</code></em> :</span></td>
223
<td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td>
224
<td>the <a href="glib-Quarks.html#GQuark"><span class="type">GQuark</span></a> associated with the string, or 0 if there is no
225
<a href="glib-Quarks.html#GQuark"><span class="type">GQuark</span></a> associated with the string.
234
<div class="refsect2" lang="en">
235
<a name="id3138427"></a><h3>
236
<a name="g-intern-string"></a>g_intern_string ()</h3>
237
<a class="indexterm" name="id3138442"></a><pre class="programlisting">const <a href="glib-Basic-Types.html#gchar">gchar</a>* g_intern_string (const <a href="glib-Basic-Types.html#gchar">gchar</a> *string);</pre>
239
Returns a canonical representation for <em class="parameter"><code>string</code></em>. Interned strings can
240
be compared for equality by comparing the pointers, instead of using <code class="function">strcmp()</code>.</p>
244
<div class="variablelist"><table border="0">
245
<col align="left" valign="top">
248
<td><span class="term"><em class="parameter"><code>string</code></em> :</span></td>
253
<td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td>
254
<td> a canonical representation for the string
260
<p class="since">Since 2.10
264
<div class="refsect2" lang="en">
265
<a name="id3138529"></a><h3>
266
<a name="g-intern-static-string"></a>g_intern_static_string ()</h3>
267
<a class="indexterm" name="id3138545"></a><pre class="programlisting">const <a href="glib-Basic-Types.html#gchar">gchar</a>* g_intern_static_string (const <a href="glib-Basic-Types.html#gchar">gchar</a> *string);</pre>
269
Returns a canonical representation for <em class="parameter"><code>string</code></em>. Interned strings can
270
be compared for equality by comparing the pointers, instead of using <code class="function">strcmp()</code>.
271
<a href="glib-Quarks.html#g-intern-static-string"><code class="function">g_intern_static_string()</code></a> does not copy the string, therefore <em class="parameter"><code>string</code></em> must
272
not be freed or modified.</p>
276
<div class="variablelist"><table border="0">
277
<col align="left" valign="top">
280
<td><span class="term"><em class="parameter"><code>string</code></em> :</span></td>
285
<td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td>
286
<td> a canonical representation for the string
292
<p class="since">Since 2.10