Project

General

Profile

Bug #1475 » glib-Arrays-utf8.html

Пример файла для импорта - Константин Власов, 07/07/2011 12:46 PM

 
1
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Arrays</title><meta name="generator" content="DocBook XSL Stylesheets V1.66.0"><link rel="start" href="index.html" title="GLib Reference Manual"><link rel="up" href="glib-data-types.html" title="GLib Data Types"><link rel="prev" href="glib-String-Chunks.html" title="String Chunks"><link rel="next" href="glib-Pointer-Arrays.html" title="Pointer Arrays"><meta name="generator" content="GTK-Doc V1.3 (XML mode)"><link rel="stylesheet" href="style.css" type="text/css"><link rel="chapter" href="glib.html" title="GLib Overview"><link rel="chapter" href="glib-fundamentals.html" title="GLib Fundamentals"><link rel="chapter" href="glib-core.html" title="GLib Core Application Support"><link rel="chapter" href="glib-utilities.html" title="GLib Utilities"><link rel="chapter" href="glib-data-types.html" title="GLib Data Types"><link rel="chapter" href="tools.html" title="GLib Tools"><link rel="index" href="ix01.html" title="Index"><link rel="index" href="ix02.html" title="Index of deprecated symbols"><link rel="index" href="ix03.html" title="Index of new symbols in 2.2"><link rel="index" href="ix04.html" title="Index of new symbols in 2.4"><link rel="index" href="ix05.html" title="Index of new symbols in 2.6"></head>
2

    
3
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
4

    
5
<script language="javascript" src="../reqtools.js"></script>
6

    
7
<table class="navigation" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2"><tr valign="middle"><td><a accesskey="p" href="glib-String-Chunks.html"><img src="left.png" width="24" height="24" border="0" alt="Prev"></a></td><td><a accesskey="u" href="glib-data-types.html"><img src="up.png" width="24" height="24" border="0" alt="Up"></a></td><td><a accesskey="h" href="index.html"><img src="home.png" width="24" height="24" border="0" alt="Home"></a></td><th width="100%" align="center">GLib Reference Manual</th><td><a accesskey="n" href="glib-Pointer-Arrays.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td></tr></table><div class="refentry" lang="en"><a name="glib-Arrays"></a><div class="titlepage"></div><div class="refnamediv"><table width="100%"><tr><td valign="top"><h2><span class="refentrytitle">Arrays</span></h2><p>Arrays &#8212; arrays of arbitrary elements which grow automatically as elements are added.</p></td><td valign="top" align="right"></td></tr></table></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
8

    
9
#include &lt;glib.h&gt;
10

    
11

    
12
            <a href="glib-Arrays.html#GArray">GArray</a>;
13
<a href="glib-Arrays.html#GArray">GArray</a>*     <a href="glib-Arrays.html#g-array-new">g_array_new</a>                     (<a href="glib-Basic-Types.html#gboolean">gboolean</a> zero_terminated,
14
                                             <a href="glib-Basic-Types.html#gboolean">gboolean</a> clear_,
15
                                             <a href="glib-Basic-Types.html#guint">guint</a> element_size);
16
<a href="glib-Arrays.html#GArray">GArray</a>*     <a href="glib-Arrays.html#g-array-sized-new">g_array_sized_new</a>               (<a href="glib-Basic-Types.html#gboolean">gboolean</a> zero_terminated,
17
                                             <a href="glib-Basic-Types.html#gboolean">gboolean</a> clear_,
18
                                             <a href="glib-Basic-Types.html#guint">guint</a> element_size,
19
                                             <a href="glib-Basic-Types.html#guint">guint</a> reserved_size);
20
#define     <a href="glib-Arrays.html#g-array-append-val">g_array_append_val</a>              (a,v)
21
<a href="glib-Arrays.html#GArray">GArray</a>*     <a href="glib-Arrays.html#g-array-append-vals">g_array_append_vals</a>             (<a href="glib-Arrays.html#GArray">GArray</a> *array,
22
                                             <a href="glib-Basic-Types.html#gconstpointer">gconstpointer</a> data,
23
                                             <a href="glib-Basic-Types.html#guint">guint</a> len);
24
#define     <a href="glib-Arrays.html#g-array-prepend-val">g_array_prepend_val</a>             (a,v)
25
<a href="glib-Arrays.html#GArray">GArray</a>*     <a href="glib-Arrays.html#g-array-prepend-vals">g_array_prepend_vals</a>            (<a href="glib-Arrays.html#GArray">GArray</a> *array,
26
                                             <a href="glib-Basic-Types.html#gconstpointer">gconstpointer</a> data,
27
                                             <a href="glib-Basic-Types.html#guint">guint</a> len);
28
#define     <a href="glib-Arrays.html#g-array-insert-val">g_array_insert_val</a>              (a,i,v)
29
<a href="glib-Arrays.html#GArray">GArray</a>*     <a href="glib-Arrays.html#g-array-insert-vals">g_array_insert_vals</a>             (<a href="glib-Arrays.html#GArray">GArray</a> *array,
30
                                             <a href="glib-Basic-Types.html#guint">guint</a> index_,
31
                                             <a href="glib-Basic-Types.html#gconstpointer">gconstpointer</a> data,
32
                                             <a href="glib-Basic-Types.html#guint">guint</a> len);
33
<a href="glib-Arrays.html#GArray">GArray</a>*     <a href="glib-Arrays.html#g-array-remove-index">g_array_remove_index</a>            (<a href="glib-Arrays.html#GArray">GArray</a> *array,
34
                                             <a href="glib-Basic-Types.html#guint">guint</a> index_);
35
<a href="glib-Arrays.html#GArray">GArray</a>*     <a href="glib-Arrays.html#g-array-remove-index-fast">g_array_remove_index_fast</a>       (<a href="glib-Arrays.html#GArray">GArray</a> *array,
36
                                             <a href="glib-Basic-Types.html#guint">guint</a> index_);
37
<a href="glib-Arrays.html#GArray">GArray</a>*     <a href="glib-Arrays.html#g-array-remove-range">g_array_remove_range</a>            (<a href="glib-Arrays.html#GArray">GArray</a> *array,
38
                                             <a href="glib-Basic-Types.html#guint">guint</a> index_,
39
                                             <a href="glib-Basic-Types.html#guint">guint</a> length);
40
void        <a href="glib-Arrays.html#g-array-sort">g_array_sort</a>                    (<a href="glib-Arrays.html#GArray">GArray</a> *array,
41
                                             <a href="glib-Doubly-Linked-Lists.html#GCompareFunc">GCompareFunc</a> compare_func);
42
void        <a href="glib-Arrays.html#g-array-sort-with-data">g_array_sort_with_data</a>          (<a href="glib-Arrays.html#GArray">GArray</a> *array,
43
                                             <a href="glib-Doubly-Linked-Lists.html#GCompareDataFunc">GCompareDataFunc</a> compare_func,
44
                                             <a href="glib-Basic-Types.html#gpointer">gpointer</a> user_data);
45
#define     <a href="glib-Arrays.html#g-array-index">g_array_index</a>                   (a,t,i)
46
<a href="glib-Arrays.html#GArray">GArray</a>*     <a href="glib-Arrays.html#g-array-set-size">g_array_set_size</a>                (<a href="glib-Arrays.html#GArray">GArray</a> *array,
47
                                             <a href="glib-Basic-Types.html#guint">guint</a> length);
48
<a href="glib-Basic-Types.html#gchar">gchar</a>*      <a href="glib-Arrays.html#g-array-free">g_array_free</a>                    (<a href="glib-Arrays.html#GArray">GArray</a> *array,
49
                                             <a href="glib-Basic-Types.html#gboolean">gboolean</a> free_segment);
50
</pre></div><div class="refsect1" lang="en"><a name="id3224671"></a><h2>Description</h2><p>
51
Arrays are similar to standard C arrays, except that they grow automatically
52
as elements are added.
53
</p><p>
54
Array elements can be of any size (though all elements of one array are the
55
same size), and the array can be automatically cleared to '0's and
56
zero-terminated.
57
</p><p>
58
To create a new array use <a href="glib-Arrays.html#g-array-new"><tt class="function">g_array_new()</tt></a>.
59
</p><p>
60
To add elements to an array, use <a href="glib-Arrays.html#g-array-append-val"><tt class="function">g_array_append_val()</tt></a>, <a href="glib-Arrays.html#g-array-append-vals"><tt class="function">g_array_append_vals()</tt></a>,
61
<a href="glib-Arrays.html#g-array-prepend-val"><tt class="function">g_array_prepend_val()</tt></a>, and <a href="glib-Arrays.html#g-array-prepend-vals"><tt class="function">g_array_prepend_vals()</tt></a>.
62
</p><p>
63
To access an element of an array, use <a href="glib-Arrays.html#g-array-index"><tt class="function">g_array_index()</tt></a>.
64
</p><p>
65
To set the size of an array, use <a href="glib-Arrays.html#g-array-set-size"><tt class="function">g_array_set_size()</tt></a>.
66
</p><p>
67
To free an array, use <a href="glib-Arrays.html#g-array-free"><tt class="function">g_array_free()</tt></a>.
68
</p><div class="example"><a name="id3224791"></a><p class="title"><b>Example 3. Using a <span class="structname">GArray</span> to store <span class="type">gint</span> values</b></p><pre class="programlisting">
69
  GArray *garray;
70
  gint i;
71

    
72
  /* We create a new array to store gint values.
73
     We don't want it zero-terminated or cleared to 0's. */
74
  garray = g_array_new (FALSE, FALSE, sizeof (gint));
75
  for (i = 0; i &lt; 10000; i++)
76
    g_array_append_val (garray, i);
77

    
78
  for (i = 0; i &lt; 10000; i++)
79
    if (g_array_index (garray, gint, i) != i)
80
      g_print ("ERROR: got %d instead of %d\n",
81
               g_array_index (garray, gint, i), i);
82

    
83
  g_array_free (garray, TRUE);
84
</pre></div></div><div class="refsect1" lang="en"><a name="id3224809"></a><h2>Details</h2><div class="refsect2" lang="en"><a name="id3224826"></a><h3><a name="GArray"></a>GArray</h3><a class="indexterm" name="id3224834"></a><pre class="programlisting">typedef struct {
85
  gchar *data;
86
  guint len;
87
} GArray;
88
</pre><p>
89
Contains the public fields of an Array.
90
</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><a href="glib-Basic-Types.html#gchar">gchar</a> *<i class="structfield"><tt>data</tt></i>;</span></td><td>a pointer to the element data. The data may be moved as elements are
91
added to the <a href="glib-Arrays.html#GArray"><span class="type">GArray</span></a>.
92
</td></tr><tr><td><span class="term"><a href="glib-Basic-Types.html#guint">guint</a> <i class="structfield"><tt>len</tt></i>;</span></td><td>the number of elements in the <a href="glib-Arrays.html#GArray"><span class="type">GArray</span></a>.
93

    
94
</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3224920"></a><h3><a name="g-array-new"></a>g_array_new ()</h3><a class="indexterm" name="id3224930"></a><pre class="programlisting"><a href="glib-Arrays.html#GArray">GArray</a>*     g_array_new                     (<a href="glib-Basic-Types.html#gboolean">gboolean</a> zero_terminated,
95
                                             <a href="glib-Basic-Types.html#gboolean">gboolean</a> clear_,
96
                                             <a href="glib-Basic-Types.html#guint">guint</a> element_size);</pre><p>
97
Creates a new <a href="glib-Arrays.html#GArray"><span class="type">GArray</span></a>.
98
</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><i class="parameter"><tt>zero_terminated</tt></i> :</span></td><td><tt class="literal">TRUE</tt> if the array should have an extra element at the end
99
which is set to 0.
100
</td></tr><tr><td><span class="term"><i class="parameter"><tt>clear_</tt></i> :</span></td><td><tt class="literal">TRUE</tt> if <a href="glib-Arrays.html#GArray"><span class="type">GArray</span></a> elements should be automatically cleared to 0
101
when they are allocated.
102
</td></tr><tr><td><span class="term"><i class="parameter"><tt>element_size</tt></i> :</span></td><td>the size of each element in bytes.
103
</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td>the new <a href="glib-Arrays.html#GArray"><span class="type">GArray</span></a>.
104

    
105

    
106
</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3225066"></a><h3><a name="g-array-sized-new"></a>g_array_sized_new ()</h3><a class="indexterm" name="id3225077"></a><pre class="programlisting"><a href="glib-Arrays.html#GArray">GArray</a>*     g_array_sized_new               (<a href="glib-Basic-Types.html#gboolean">gboolean</a> zero_terminated,
107
                                             <a href="glib-Basic-Types.html#gboolean">gboolean</a> clear_,
108
                                             <a href="glib-Basic-Types.html#guint">guint</a> element_size,
109
                                             <a href="glib-Basic-Types.html#guint">guint</a> reserved_size);</pre><p>
110
Creates a new <a href="glib-Arrays.html#GArray"><span class="type">GArray</span></a> with <i class="parameter"><tt>reserved_size</tt></i> elements
111
preallocated. This avoids frequent reallocation, if you are going to
112
add many elements to the array. Note however that the size of the
113
array is still 0.
114
</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><i class="parameter"><tt>zero_terminated</tt></i> :</span></td><td><tt class="literal">TRUE</tt> if the array should have an extra element at the end with all bits cleared.
115
</td></tr><tr><td><span class="term"><i class="parameter"><tt>clear_</tt></i> :</span></td><td><tt class="literal">TRUE</tt> if all bits in the array should be cleared to 0 on allocation.
116
</td></tr><tr><td><span class="term"><i class="parameter"><tt>element_size</tt></i> :</span></td><td>size of each element in the array.
117
</td></tr><tr><td><span class="term"><i class="parameter"><tt>reserved_size</tt></i> :</span></td><td>number of elements preallocated.
118
</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td>the new <a href="glib-Arrays.html#GArray"><span class="type">GArray</span></a>.
119

    
120

    
121
</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3225236"></a><h3><a name="g-array-append-val"></a>g_array_append_val()</h3><a class="indexterm" name="id3225247"></a><pre class="programlisting">#define     g_array_append_val(a,v)</pre><p>
122
Adds the value on to the end of the array.
123
The array will grow in size automatically if necessary.
124
</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>
125
<a href="glib-Arrays.html#g-array-append-val"><tt class="function">g_array_append_val()</tt></a> is a macro which uses a reference to the value
126
parameter <i class="parameter"><tt>v</tt></i>. This means that you cannot use it with literal values
127
such as "27". You must use variables.
128
</p></div><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><i class="parameter"><tt>a</tt></i> :</span></td><td>a <a href="glib-Arrays.html#GArray"><span class="type">GArray</span></a>.
129
</td></tr><tr><td><span class="term"><i class="parameter"><tt>v</tt></i> :</span></td><td>the value to append to the <a href="glib-Arrays.html#GArray"><span class="type">GArray</span></a>.
130
</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td>the <a href="glib-Arrays.html#GArray"><span class="type">GArray</span></a>.
131

    
132

    
133
</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3225354"></a><h3><a name="g-array-append-vals"></a>g_array_append_vals ()</h3><a class="indexterm" name="id3225365"></a><pre class="programlisting"><a href="glib-Arrays.html#GArray">GArray</a>*     g_array_append_vals             (<a href="glib-Arrays.html#GArray">GArray</a> *array,
134
                                             <a href="glib-Basic-Types.html#gconstpointer">gconstpointer</a> data,
135
                                             <a href="glib-Basic-Types.html#guint">guint</a> len);</pre><p>
136
Adds <i class="parameter"><tt>len</tt></i> elements onto the end of the array.
137
</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><i class="parameter"><tt>array</tt></i> :</span></td><td>a <a href="glib-Arrays.html#GArray"><span class="type">GArray</span></a>.
138
</td></tr><tr><td><span class="term"><i class="parameter"><tt>data</tt></i> :</span></td><td>a pointer to the elements to append to the end of the array.
139
</td></tr><tr><td><span class="term"><i class="parameter"><tt>len</tt></i> :</span></td><td>the number of elements to append.
140
</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td>the <a href="glib-Arrays.html#GArray"><span class="type">GArray</span></a>.
141

    
142

    
143
</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3225487"></a><h3><a name="g-array-prepend-val"></a>g_array_prepend_val()</h3><a class="indexterm" name="id3225498"></a><pre class="programlisting">#define     g_array_prepend_val(a,v)</pre><p>
144
Adds the value on to the start of the array.
145
The array will grow in size automatically if necessary.
146
</p><p>
147
This operation is slower than <a href="glib-Arrays.html#g-array-append-val"><tt class="function">g_array_append_val()</tt></a> since the existing elements
148
in the array have to be moved to make space for the new element.
149
</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>
150
<a href="glib-Arrays.html#g-array-prepend-val"><tt class="function">g_array_prepend_val()</tt></a> is a macro which uses a reference to the value
151
parameter <i class="parameter"><tt>v</tt></i>. This means that you cannot use it with literal values
152
such as "27". You must use variables.
153
</p></div><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><i class="parameter"><tt>a</tt></i> :</span></td><td>a <a href="glib-Arrays.html#GArray"><span class="type">GArray</span></a>.
154
</td></tr><tr><td><span class="term"><i class="parameter"><tt>v</tt></i> :</span></td><td>the value to prepend to the <a href="glib-Arrays.html#GArray"><span class="type">GArray</span></a>.
155
</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td>the <a href="glib-Arrays.html#GArray"><span class="type">GArray</span></a>.
156

    
157

    
158
</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3225622"></a><h3><a name="g-array-prepend-vals"></a>g_array_prepend_vals ()</h3><a class="indexterm" name="id3225633"></a><pre class="programlisting"><a href="glib-Arrays.html#GArray">GArray</a>*     g_array_prepend_vals            (<a href="glib-Arrays.html#GArray">GArray</a> *array,
159
                                             <a href="glib-Basic-Types.html#gconstpointer">gconstpointer</a> data,
160
                                             <a href="glib-Basic-Types.html#guint">guint</a> len);</pre><p>
161
Adds <i class="parameter"><tt>len</tt></i> elements onto the start of the array.
162
</p><p>
163
This operation is slower than <a href="glib-Arrays.html#g-array-append-vals"><tt class="function">g_array_append_vals()</tt></a> since the existing elements
164
in the array have to be moved to make space for the new elements.
165
</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><i class="parameter"><tt>array</tt></i> :</span></td><td>a <a href="glib-Arrays.html#GArray"><span class="type">GArray</span></a>.
166
</td></tr><tr><td><span class="term"><i class="parameter"><tt>data</tt></i> :</span></td><td>a pointer to the elements to prepend to the start of the array.
167
</td></tr><tr><td><span class="term"><i class="parameter"><tt>len</tt></i> :</span></td><td>the number of elements to prepend.
168
</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td>the <a href="glib-Arrays.html#GArray"><span class="type">GArray</span></a>.
169

    
170

    
171
</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3225772"></a><h3><a name="g-array-insert-val"></a>g_array_insert_val()</h3><a class="indexterm" name="id3225783"></a><pre class="programlisting">#define     g_array_insert_val(a,i,v)</pre><p>
172
Inserts an element into an array at the given index.
173
</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>
174
<a href="glib-Arrays.html#g-array-insert-val"><tt class="function">g_array_insert_val()</tt></a> is a macro which uses a reference to the value
175
parameter <i class="parameter"><tt>v</tt></i>. This means that you cannot use it with literal values
176
such as "27". You must use variables.
177
</p></div><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><i class="parameter"><tt>a</tt></i> :</span></td><td>a <a href="glib-Arrays.html#GArray"><span class="type">GArray</span></a>.
178
</td></tr><tr><td><span class="term"><i class="parameter"><tt>i</tt></i> :</span></td><td>the index to place the element at.
179
</td></tr><tr><td><span class="term"><i class="parameter"><tt>v</tt></i> :</span></td><td>the value to insert into the array.
180
</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td>the <a href="glib-Arrays.html#GArray"><span class="type">GArray</span></a>.
181

    
182

    
183
</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3225896"></a><h3><a name="g-array-insert-vals"></a>g_array_insert_vals ()</h3><a class="indexterm" name="id3225907"></a><pre class="programlisting"><a href="glib-Arrays.html#GArray">GArray</a>*     g_array_insert_vals             (<a href="glib-Arrays.html#GArray">GArray</a> *array,
184
                                             <a href="glib-Basic-Types.html#guint">guint</a> index_,
185
                                             <a href="glib-Basic-Types.html#gconstpointer">gconstpointer</a> data,
186
                                             <a href="glib-Basic-Types.html#guint">guint</a> len);</pre><p>
187
Inserts <i class="parameter"><tt>len</tt></i> elements into a <a href="glib-Arrays.html#GArray"><span class="type">GArray</span></a> at the given index.
188
</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><i class="parameter"><tt>array</tt></i> :</span></td><td>a <a href="glib-Arrays.html#GArray"><span class="type">GArray</span></a>.
189
</td></tr><tr><td><span class="term"><i class="parameter"><tt>index_</tt></i> :</span></td><td>the index to place the elements at.
190
</td></tr><tr><td><span class="term"><i class="parameter"><tt>data</tt></i> :</span></td><td>a pointer to the elements to insert.
191
</td></tr><tr><td><span class="term"><i class="parameter"><tt>len</tt></i> :</span></td><td>the number of elements to insert.
192
</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td>the <a href="glib-Arrays.html#GArray"><span class="type">GArray</span></a>.
193

    
194

    
195
</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3226059"></a><h3><a name="g-array-remove-index"></a>g_array_remove_index ()</h3><a class="indexterm" name="id3226069"></a><pre class="programlisting"><a href="glib-Arrays.html#GArray">GArray</a>*     g_array_remove_index            (<a href="glib-Arrays.html#GArray">GArray</a> *array,
196
                                             <a href="glib-Basic-Types.html#guint">guint</a> index_);</pre><p>
197
Removes the element at the given index from a <a href="glib-Arrays.html#GArray"><span class="type">GArray</span></a>.
198
The following elements are moved down one place.
199
</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><i class="parameter"><tt>array</tt></i> :</span></td><td>a <a href="glib-Arrays.html#GArray"><span class="type">GArray</span></a>.
200
</td></tr><tr><td><span class="term"><i class="parameter"><tt>index_</tt></i> :</span></td><td>the index of the element to remove.
201
</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td>the <a href="glib-Arrays.html#GArray"><span class="type">GArray</span></a>.
202

    
203

    
204
</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3226173"></a><h3><a name="g-array-remove-index-fast"></a>g_array_remove_index_fast ()</h3><a class="indexterm" name="id3226185"></a><pre class="programlisting"><a href="glib-Arrays.html#GArray">GArray</a>*     g_array_remove_index_fast       (<a href="glib-Arrays.html#GArray">GArray</a> *array,
205
                                             <a href="glib-Basic-Types.html#guint">guint</a> index_);</pre><p>
206
Removes the element at the given index from a <a href="glib-Arrays.html#GArray"><span class="type">GArray</span></a>.
207
The last element in the array is used to fill in the space, so this function
208
does not preserve the order of the <a href="glib-Arrays.html#GArray"><span class="type">GArray</span></a>. But it is faster than
209
<a href="glib-Arrays.html#g-array-remove-index"><tt class="function">g_array_remove_index()</tt></a>.
210
</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><i class="parameter"><tt>array</tt></i> :</span></td><td>a <i class="parameter"><tt>GArray</tt></i>.
211
</td></tr><tr><td><span class="term"><i class="parameter"><tt>index_</tt></i> :</span></td><td>the index of the element to remove.
212
</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td>the <a href="glib-Arrays.html#GArray"><span class="type">GArray</span></a>.
213

    
214

    
215
</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3226306"></a><h3><a name="g-array-remove-range"></a>g_array_remove_range ()</h3><a class="indexterm" name="id3226316"></a><pre class="programlisting"><a href="glib-Arrays.html#GArray">GArray</a>*     g_array_remove_range            (<a href="glib-Arrays.html#GArray">GArray</a> *array,
216
                                             <a href="glib-Basic-Types.html#guint">guint</a> index_,
217
                                             <a href="glib-Basic-Types.html#guint">guint</a> length);</pre><p>
218
Removes the given number of elements starting at the given index from a
219
<a href="glib-Arrays.html#GArray"><span class="type">GArray</span></a>.  The following elements are moved to close the gap.
220
</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><i class="parameter"><tt>array</tt></i> :</span></td><td>a <i class="parameter"><tt>GArray</tt></i>.
221
</td></tr><tr><td><span class="term"><i class="parameter"><tt>index_</tt></i> :</span></td><td>the index of the first element to remove.
222
</td></tr><tr><td><span class="term"><i class="parameter"><tt>length</tt></i> :</span></td><td>the number of elements to remove.
223
</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td>the <a href="glib-Arrays.html#GArray"><span class="type">GArray</span></a>.
224
</td></tr></tbody></table></div><p>Since 2.4
225

    
226

    
227
</p></div><hr><div class="refsect2" lang="en"><a name="id3226445"></a><h3><a name="g-array-sort"></a>g_array_sort ()</h3><a class="indexterm" name="id3226455"></a><pre class="programlisting">void        g_array_sort                    (<a href="glib-Arrays.html#GArray">GArray</a> *array,
228
                                             <a href="glib-Doubly-Linked-Lists.html#GCompareFunc">GCompareFunc</a> compare_func);</pre><p>
229
Sorts a <a href="glib-Arrays.html#GArray"><span class="type">GArray</span></a> using <i class="parameter"><tt>compare_func</tt></i> which should be a <tt class="function">qsort()</tt>-style comparison
230
function (returns -1 for first arg is less than second arg, 0 for equal, 1 if
231
first arg is greater than second arg).
232
</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><i class="parameter"><tt>array</tt></i> :</span></td><td>a <a href="glib-Arrays.html#GArray"><span class="type">GArray</span></a>.
233
</td></tr><tr><td><span class="term"><i class="parameter"><tt>compare_func</tt></i> :</span></td><td>comparison function.
234

    
235

    
236
</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3226558"></a><h3><a name="g-array-sort-with-data"></a>g_array_sort_with_data ()</h3><a class="indexterm" name="id3226569"></a><pre class="programlisting">void        g_array_sort_with_data          (<a href="glib-Arrays.html#GArray">GArray</a> *array,
237
                                             <a href="glib-Doubly-Linked-Lists.html#GCompareDataFunc">GCompareDataFunc</a> compare_func,
238
                                             <a href="glib-Basic-Types.html#gpointer">gpointer</a> user_data);</pre><p>
239
Like <a href="glib-Arrays.html#g-array-sort"><tt class="function">g_array_sort()</tt></a>, but the comparison function receives a user data
240
argument.
241
</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><i class="parameter"><tt>array</tt></i> :</span></td><td>a <a href="glib-Arrays.html#GArray"><span class="type">GArray</span></a>.
242
</td></tr><tr><td><span class="term"><i class="parameter"><tt>compare_func</tt></i> :</span></td><td>comparison function.
243
</td></tr><tr><td><span class="term"><i class="parameter"><tt>user_data</tt></i> :</span></td><td>data to pass to <i class="parameter"><tt>compare_func</tt></i>.
244

    
245

    
246
</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3226685"></a><h3><a name="g-array-index"></a>g_array_index()</h3><a class="indexterm" name="id3226696"></a><pre class="programlisting">#define     g_array_index(a,t,i)</pre><p>
247
Returns the element of a <a href="glib-Arrays.html#GArray"><span class="type">GArray</span></a> at the given index.
248
The return value is cast to the given type.
249

    
250
</p><div class="example"><a name="id3226719"></a><p class="title"><b>Example 4. Getting a pointer to an element in a <span class="structname">GArray</span></b></p><pre class="programlisting">
251
  EDayViewEvent *event;
252

    
253
  /* This gets a pointer to the 3rd element in the array of EDayViewEvent
254
     structs. */
255
  event = &amp;g_array_index (events, EDayViewEvent, 3);
256
</pre></div><p>
257
</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><i class="parameter"><tt>a</tt></i> :</span></td><td>a <a href="glib-Arrays.html#GArray"><span class="type">GArray</span></a>.
258
</td></tr><tr><td><span class="term"><i class="parameter"><tt>t</tt></i> :</span></td><td>the type of the elements.
259
</td></tr><tr><td><span class="term"><i class="parameter"><tt>i</tt></i> :</span></td><td>the index of the element to return.
260
</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td>the element of the <a href="glib-Arrays.html#GArray"><span class="type">GArray</span></a> at the index given by <i class="parameter"><tt>i</tt></i>.
261

    
262

    
263
</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3226818"></a><h3><a name="g-array-set-size"></a>g_array_set_size ()</h3><a class="indexterm" name="id3226829"></a><pre class="programlisting"><a href="glib-Arrays.html#GArray">GArray</a>*     g_array_set_size                (<a href="glib-Arrays.html#GArray">GArray</a> *array,
264
                                             <a href="glib-Basic-Types.html#guint">guint</a> length);</pre><p>
265
Sets the size of the array, expanding it if necessary.
266
If the array was created with <i class="parameter"><tt>clear_</tt></i> set to <tt class="literal">TRUE</tt>, the new elements are set to 0.
267
</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><i class="parameter"><tt>array</tt></i> :</span></td><td>a <a href="glib-Arrays.html#GArray"><span class="type">GArray</span></a>.
268
</td></tr><tr><td><span class="term"><i class="parameter"><tt>length</tt></i> :</span></td><td>the new size of the <a href="glib-Arrays.html#GArray"><span class="type">GArray</span></a>.
269
</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td>the <a href="glib-Arrays.html#GArray"><span class="type">GArray</span></a>.
270

    
271

    
272
</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3226944"></a><h3><a name="g-array-free"></a>g_array_free ()</h3><a class="indexterm" name="id3226955"></a><pre class="programlisting"><a href="glib-Basic-Types.html#gchar">gchar</a>*      g_array_free                    (<a href="glib-Arrays.html#GArray">GArray</a> *array,
273
                                             <a href="glib-Basic-Types.html#gboolean">gboolean</a> free_segment);</pre><p>
274
Frees the memory allocated for the <a href="glib-Arrays.html#GArray"><span class="type">GArray</span></a>.
275
If <i class="parameter"><tt>free_segment</tt></i> is <tt class="literal">TRUE</tt> it frees the actual element data as well.
276
</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><i class="parameter"><tt>array</tt></i> :</span></td><td>a <a href="glib-Arrays.html#GArray"><span class="type">GArray</span></a>.
277
</td></tr><tr><td><span class="term"><i class="parameter"><tt>free_segment</tt></i> :</span></td><td>if <tt class="literal">TRUE</tt> the actual element data is freed as well.
278
</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td>the element data if <i class="parameter"><tt>free_segment</tt></i> is <tt class="literal">FALSE</tt>, otherwise <tt class="literal">NULL</tt>
279

    
280

    
281
</td></tr></tbody></table></div></div></div></div><table class="navigation" width="100%" summary="Navigation footer" cellpadding="2" cellspacing="0"><tr valign="middle"><td align="left"><a accesskey="p" href="glib-String-Chunks.html"><b>&lt;&lt; String Chunks</b></a></td><td align="right"><a accesskey="n" href="glib-Pointer-Arrays.html"><b>Pointer Arrays &gt;&gt;</b></a></td></tr></table></body></html>
    (1-1/1)