Project

General

Profile

Reqeditor-getting-started » glib-Arrays-utf8.xhtml

Yuriy Shekochihin, 01/11/2010 11:50 AM

 
<?xml version="1.0" encoding="UTF-8"?>
<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml"><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><body link="#0000ff" text="black" vlink="#840084" bgcolor="white" alink="#0000ff">
<script language="javascript" src="../reqtools.js"> </script>
<table width="100%" cellspacing="2" cellpadding="2" class="navigation" summary="Navigation header"><tbody><tr valign="middle"><td><a accesskey="p" href="glib-String-Chunks.html"><img height="24" width="24" border="0" src="left.png" alt="Prev"/></a></td><td><a accesskey="u" href="glib-data-types.html"><img height="24" width="24" border="0" src="up.png" alt="Up"/></a></td><td><a accesskey="h" href="index.html"><img height="24" width="24" border="0" src="home.png" alt="Home"/></a></td><th width="100%" align="center">GLib Reference Manual</th><td><a accesskey="n" href="glib-Pointer-Arrays.html"><img height="24" width="24" border="0" src="right.png" alt="Next"/></a></td></tr></tbody></table><div lang="en" class="refentry"><a name="glib-Arrays"/><div class="titlepage"/><div class="refnamediv"><table width="100%"><tbody><tr><td valign="top"><h2><span class="refentrytitle">Arrays</span></h2><p><span class="reqstart" id="c0e6e40b-96b3-4cf6-aeb1-623bd44b0f07"> </span><span class="wrap" style="background-color: rgb(255, 255, 153);" id="">Arrays — arrays <span class="reqelem" id=""> </span><a name="reqc0e6e40b-96b3-4cf6-aeb1-623bd44b0f07"> </a></span><span class="reqend" id="c0e6e40b-96b3-4cf6-aeb1-623bd44b0f07"> </span>of arbitrary <span class="reqstart" id="452208ed-5409-44c3-ac10-ce86573c9a30"> </span><span class="wrap" style="background-color: rgb(255, 255, 153);">elements<span class="reqelem" id="/Test3"> </span><a name="req452208ed-5409-44c3-ac10-ce86573c9a30"> </a></span><span class="reqend" id="452208ed-5409-44c3-ac10-ce86573c9a30"> </span> <span class="reqstart" id="914a3d62-e1e1-4214-a63b-f07d9eaf7b38"> </span><span class="wrap" style="background-color: rgb(255, 255, 153);">which<span class="reqelem" id=""> </span><a name="req914a3d62-e1e1-4214-a63b-f07d9eaf7b38"> </a></span><span class="reqend" id="914a3d62-e1e1-4214-a63b-f07d9eaf7b38"> </span> grow <span class="reqstart" id="751c61a1-c8f5-48e3-8f83-540a5e5021f1"> </span><span class="wrap" style="background-color: rgb(255, 255, 153);">automatically<span class="reqelem" id=""> </span><a name="req751c61a1-c8f5-48e3-8f83-540a5e5021f1"> </a></span><span class="reqend" id="751c61a1-c8f5-48e3-8f83-540a5e5021f1"> </span> as elements are <span class="reqstart" id="2b9305fc-6a2c-4fdc-aeca-c5f89e98d481"> </span><span class="wrap" style="background-color: rgb(255, 255, 153);">added<span class="reqelem" id="/Test2"> </span><a name="req2b9305fc-6a2c-4fdc-aeca-c5f89e98d481"> </a></span><span class="reqend" id="2b9305fc-6a2c-4fdc-aeca-c5f89e98d481"> </span>.</p></td><td valign="top" align="right"/></tr></tbody></table></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis"> #include &lt;glib.h&gt;
<a href="glib-Arrays.html#GArray">GArray</a>;
<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,
<a href="glib-Basic-Types.html#gboolean">gboolean</a> clear_,
<a href="glib-Basic-Types.html#guint">guint</a> element_size);
<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,
<a href="glib-Basic-Types.html#gboolean">gboolean</a> clear_,
<a href="glib-Basic-Types.html#guint">guint</a> element_size,
<a href="glib-Basic-Types.html#guint">guint</a> reserved_size);
#define
<a href="glib-Arrays.html#g-array-append-val">g_array_append_val</a> (a,v)
<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,
<a href="glib-Basic-Types.html#gconstpointer">gconstpointer</a> data,
<a href="glib-Basic-Types.html#guint">guint</a> len);
#define
<a href="glib-Arrays.html#g-array-prepend-val">g_array_prepend_val</a> (a,v)
<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,
<a href="glib-Basic-Types.html#gconstpointer">gconstpointer</a> data,
<a href="glib-Basic-Types.html#guint">guint</a> len);
#define
<a href="glib-Arrays.html#g-array-insert-val">g_array_insert_val</a> (a,i,v)
<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,
<a href="glib-Basic-Types.html#guint">guint</a> index_,
<a href="glib-Basic-Types.html#gconstpointer">gconstpointer</a> data,
<a href="glib-Basic-Types.html#guint">guint</a> len);
<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,
<a href="glib-Basic-Types.html#guint">guint</a> index_);
<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,
<a href="glib-Basic-Types.html#guint">guint</a> index_);
<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,
<a href="glib-Basic-Types.html#guint">guint</a> index_,
<a href="glib-Basic-Types.html#guint">guint</a> length);
void
<a href="glib-Arrays.html#g-array-sort">g_array_sort</a> (
<a href="glib-Arrays.html#GArray">GArray</a> *array,
<a href="glib-Doubly-Linked-Lists.html#GCompareFunc">GCompareFunc</a> compare_func);
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,
<a href="glib-Doubly-Linked-Lists.html#GCompareDataFunc">GCompareDataFunc</a> compare_func,
<a href="glib-Basic-Types.html#gpointer">gpointer</a> user_data);
#define
<a href="glib-Arrays.html#g-array-index">g_array_index</a> (a,t,i)
<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,
<a href="glib-Basic-Types.html#guint">guint</a> length);
<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,
<a href="glib-Basic-Types.html#gboolean">gboolean</a> free_segment); </pre></div><div lang="en" class="refsect1"><a name="id3224671"/><h2>Description</h2><p> Arrays are similar to standard C arrays<span class="reqstart" id="405f51c5-6b5b-4be4-951a-7ec50eb22fe7"> </span><span class="wrap" style="background-color: rgb(255, 255, 153);">, except<span class="reqelem" id="/Test2"> </span><a name="req405f51c5-6b5b-4be4-951a-7ec50eb22fe7"> </a></span><span class="reqend" id="405f51c5-6b5b-4be4-951a-7ec50eb22fe7"> </span> that they grow automatically
as elements are added. </p><p> Array elements can be of any size (though all elements of one array are the
same size), and the array can be automatically cleared to '0's and
zero-terminated. </p><p> To create a new array use
<a href="glib-Arrays.html#g-array-new"><tt class="function">g_array_new()</tt></a>. </p><p> 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>,
<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>. </p><p> To access an element of an array, use
<a href="glib-Arrays.html#g-array-index"><tt class="function">g_array_index()</tt></a>. </p><p> 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>. </p><p> To free an array, use
<a href="glib-Arrays.html#g-array-free"><tt class="function">g_array_free()</tt></a>. </p><div class="example"><a name="id3224791"/><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"> GArray *garray;
gint i;

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

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

g_array_free (garray, TRUE); </pre></div></div><div lang="en" class="refsect1"><a name="id3224809"/><h2>Details</h2><div lang="en" class="refsect2"><a name="id3224826"/><h3><a name="GArray"/>GArray</h3><a class="indexterm" name="id3224834"/><pre class="programlisting">typedef struct {
gchar *data;
guint len;
} GArray; </pre><p> Contains the public fields of an Array. </p><div class="variablelist"><table border="0"><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
added to the
<a href="glib-Arrays.html#GArray"><span class="type">GArray</span></a>. </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>. </td></tr></tbody></table></div></div><hr/><div lang="en" class="refsect2"> <a name="id3224920"/><h3><a name="g-array-new"/>g_array_new ()</h3><a class="indexterm" name="id3224930"/><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,
<a href="glib-Basic-Types.html#gboolean">gboolean</a> clear_,
<a href="glib-Basic-Types.html#guint">guint</a> element_size);</pre><p> Creates a new
<a href="glib-Arrays.html#GArray"><span class="type">GArray</span></a>. </p><div class="variablelist"><table border="0"><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
which is set to 0. </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
when they are allocated. </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. </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>. </td></tr></tbody></table></div></div><hr/><div lang="en" class="refsect2"><a name="id3225066"/><h3><a name="g-array-sized-new"/>g_array_sized_new ()</h3><a class="indexterm" name="id3225077"/><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,
<a href="glib-Basic-Types.html#gboolean">gboolean</a> clear_,
<a href="glib-Basic-Types.html#guint">guint</a> element_size,
<a href="glib-Basic-Types.html#guint">guint</a> reserved_size);</pre><p> 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
preallocated. This avoids frequent reallocation, if you are going to
add many elements to the array. Note however that the size of the
array is still 0. </p><div class="variablelist"><table border="0"><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. </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. </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. </td></tr><tr><td><span class="term"><i class="parameter"><tt>reserved_size</tt></i> :</span></td><td>number of elements preallocated. </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>. </td></tr></tbody></table></div></div><hr/><div lang="en" class="refsect2"><a name="id3225236"/><h3><a name="g-array-append-val"/>g_array_append_val()</h3><a class="indexterm" name="id3225247"/><pre class="programlisting">#define g_array_append_val(a,v)</pre><p> Adds the value on to the end of the array.
The array will grow in size automatically if necessary. </p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>
<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
parameter
<i class="parameter"><tt>v</tt></i>. This means that you cannot use it with literal values
such as "27". You must use variables. </p></div><div class="variablelist"><table border="0"><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>. </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>. </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>. </td></tr></tbody></table></div></div><hr/><div lang="en" class="refsect2"><a name="id3225354"/><h3><a name="g-array-append-vals"/>g_array_append_vals ()</h3><a class="indexterm" name="id3225365"/><pre class="programlisting"><a href="glib-Arrays.html#GArray">GArray</a>* g_array_append_vals (
<a href="glib-Arrays.html#GArray">GArray</a> *array,
<a href="glib-Basic-Types.html#gconstpointer">gconstpointer</a> data,
<a href="glib-Basic-Types.html#guint">guint</a> len);</pre><p> Adds
<i class="parameter"><tt>len</tt></i> elements onto the end of the array. </p><div class="variablelist"><table border="0"><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>. </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. </td></tr><tr><td><span class="term"><i class="parameter"><tt>len</tt></i> :</span></td><td>the number of elements to append. </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>. </td></tr></tbody></table></div></div><hr/><div lang="en" class="refsect2"><a name="id3225487"/><h3><a name="g-array-prepend-val"/>g_array_prepend_val()</h3><a class="indexterm" name="id3225498"/><pre class="programlisting">#define g_array_prepend_val(a,v)</pre><p> Adds the value on to the start of the array.
The array will grow in size automatically if necessary. </p><p> 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
in the array have to be moved to make space for the new element. </p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>
<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
parameter
<i class="parameter"><tt>v</tt></i>. This means that you cannot use it with literal values
such as "27". You must use variables. </p></div><div class="variablelist"><table border="0"><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>. </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>. </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>. </td></tr></tbody></table></div></div><hr/><div lang="en" class="refsect2"><a name="id3225622"/><h3><a name="g-array-prepend-vals"/>g_array_prepend_vals ()</h3><a class="indexterm" name="id3225633"/><pre class="programlisting"><a href="glib-Arrays.html#GArray">GArray</a>* g_array_prepend_vals (
<a href="glib-Arrays.html#GArray">GArray</a> *array,
<a href="glib-Basic-Types.html#gconstpointer">gconstpointer</a> data,
<a href="glib-Basic-Types.html#guint">guint</a> len);</pre><p> Adds
<i class="parameter"><tt>len</tt></i> elements onto the start of the array. </p><p> 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
in the array have to be moved to make space for the new elements. </p><div class="variablelist"><table border="0"><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>. </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. </td></tr><tr><td><span class="term"><i class="parameter"><tt>len</tt></i> :</span></td><td>the number of elements to prepend. </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>. </td></tr></tbody></table></div></div><hr/><div lang="en" class="refsect2"><a name="id3225772"/><h3><a name="g-array-insert-val"/>g_array_insert_val()</h3><a class="indexterm" name="id3225783"/><pre class="programlisting">#define g_array_insert_val(a,i,v)</pre><p> Inserts an element into an array at the given index. </p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>
<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
parameter
<i class="parameter"><tt>v</tt></i>. This means that you cannot use it with literal values
such as "27". You must use variables. </p></div><div class="variablelist"><table border="0"><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>. </td></tr><tr><td><span class="term"><i class="parameter"><tt>i</tt></i> :</span></td><td>the index to place the element at. </td></tr><tr><td><span class="term"><i class="parameter"><tt>v</tt></i> :</span></td><td>the value to insert into the array. </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>. </td></tr></tbody></table></div></div><hr/><div lang="en" class="refsect2"><a name="id3225896"/><h3><a name="g-array-insert-vals"/>g_array_insert_vals ()</h3><a class="indexterm" name="id3225907"/><pre class="programlisting"><a href="glib-Arrays.html#GArray">GArray</a>* g_array_insert_vals (
<a href="glib-Arrays.html#GArray">GArray</a> *array,
<a href="glib-Basic-Types.html#guint">guint</a> index_,
<a href="glib-Basic-Types.html#gconstpointer">gconstpointer</a> data,
<a href="glib-Basic-Types.html#guint">guint</a> len);</pre><p> 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. </p><div class="variablelist"><table border="0"><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>. </td></tr><tr><td><span class="term"><i class="parameter"><tt>index_</tt></i> :</span></td><td>the index to place the elements at. </td></tr><tr><td><span class="term"><i class="parameter"><tt>data</tt></i> :</span></td><td>a pointer to the elements to insert. </td></tr><tr><td><span class="term"><i class="parameter"><tt>len</tt></i> :</span></td><td>the number of elements to insert. </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>. </td></tr></tbody></table></div></div><hr/><div lang="en" class="refsect2"><a name="id3226059"/><h3><a name="g-array-remove-index"/>g_array_remove_index ()</h3><a class="indexterm" name="id3226069"/><pre class="programlisting"><a href="glib-Arrays.html#GArray">GArray</a>* g_array_remove_index (
<a href="glib-Arrays.html#GArray">GArray</a> *array,
<a href="glib-Basic-Types.html#guint">guint</a> index_);</pre><p> Removes the element at the given index from a
<a href="glib-Arrays.html#GArray"><span class="type">GArray</span></a>.
The following elements are moved down one place. </p><div class="variablelist"><table border="0"><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>. </td></tr><tr><td><span class="term"><i class="parameter"><tt>index_</tt></i> :</span></td><td>the index of the element to remove. </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>. </td></tr></tbody></table></div></div><hr/><div lang="en" class="refsect2"><a name="id3226173"/><h3><a name="g-array-remove-index-fast"/>g_array_remove_index_fast ()</h3><a class="indexterm" name="id3226185"/><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,
<a href="glib-Basic-Types.html#guint">guint</a> index_);</pre><p> Removes the element at the given index from a
<a href="glib-Arrays.html#GArray"><span class="type">GArray</span></a>.
The last element in the array is used to fill in the space, so this function
does not preserve the order of the
<a href="glib-Arrays.html#GArray"><span class="type">GArray</span></a>. But it is faster than
<a href="glib-Arrays.html#g-array-remove-index"><tt class="function">g_array_remove_index()</tt></a>. </p><div class="variablelist"><table border="0"><tbody><tr><td><span class="term"><i class="parameter"><tt>array</tt></i> :</span></td><td>a
<i class="parameter"><tt>GArray</tt></i>. </td></tr><tr><td><span class="term"><i class="parameter"><tt>index_</tt></i> :</span></td><td>the index of the element to remove. </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>. </td></tr></tbody></table></div></div><hr/><div lang="en" class="refsect2"><a name="id3226306"/><h3><a name="g-array-remove-range"/>g_array_remove_range ()</h3><a class="indexterm" name="id3226316"/><pre class="programlisting"><a href="glib-Arrays.html#GArray">GArray</a>* g_array_remove_range (
<a href="glib-Arrays.html#GArray">GArray</a> *array,
<a href="glib-Basic-Types.html#guint">guint</a> index_,
<a href="glib-Basic-Types.html#guint">guint</a> length);</pre><p> Removes the given number of elements starting at the given index from a
<a href="glib-Arrays.html#GArray"><span class="type">GArray</span></a>. The following elements are moved to close the gap. </p><div class="variablelist"><table border="0"><tbody><tr><td><span class="term"><i class="parameter"><tt>array</tt></i> :</span></td><td>a
<i class="parameter"><tt>GArray</tt></i>. </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. </td></tr><tr><td><span class="term"><i class="parameter"><tt>length</tt></i> :</span></td><td>the number of elements to remove. </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>. </td></tr></tbody></table></div><p>Since 2.4 </p></div><hr/><div lang="en" class="refsect2"><a name="id3226445"/><h3><a name="g-array-sort"/>g_array_sort ()</h3><a class="indexterm" name="id3226455"/><pre class="programlisting">void g_array_sort (
<a href="glib-Arrays.html#GArray">GArray</a> *array,
<a href="glib-Doubly-Linked-Lists.html#GCompareFunc">GCompareFunc</a> compare_func);</pre><p> 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
function (returns -1 for first arg is less than second arg, 0 for equal, 1 if
first arg is greater than second arg). </p><div class="variablelist"><table border="0"><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>. </td></tr><tr><td><span class="term"><i class="parameter"><tt>compare_func</tt></i> :</span></td><td>comparison function. </td></tr></tbody></table></div></div><hr/><div lang="en" class="refsect2"><a name="id3226558"/><h3><a name="g-array-sort-with-data"/>g_array_sort_with_data ()</h3><a class="indexterm" name="id3226569"/><pre class="programlisting">void g_array_sort_with_data (
<a href="glib-Arrays.html#GArray">GArray</a> *array,
<a href="glib-Doubly-Linked-Lists.html#GCompareDataFunc">GCompareDataFunc</a> compare_func,
<a href="glib-Basic-Types.html#gpointer">gpointer</a> user_data);</pre><p> 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
argument. </p><div class="variablelist"><table border="0"><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>. </td></tr><tr><td><span class="term"><i class="parameter"><tt>compare_func</tt></i> :</span></td><td>comparison function. </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>. </td></tr></tbody></table></div></div><hr/><div lang="en" class="refsect2"><a name="id3226685"/><h3><a name="g-array-index"/>g_array_index()</h3><a class="indexterm" name="id3226696"/><pre class="programlisting">#define g_array_index(a,t,i)</pre><p> Returns the element of a
<a href="glib-Arrays.html#GArray"><span class="type">GArray</span></a> at the given index.
The return value is cast to the given type. </p><div class="example"><a name="id3226719"/><p class="title"><b>Example 4. Getting a pointer to an element in a
<span class="structname">GArray</span></b></p><pre class="programlisting"> EDayViewEvent *event;

/* This gets a pointer to the 3rd element in the array of EDayViewEvent
structs. */
event = &amp;g_array_index (events, EDayViewEvent, 3); </pre></div><p> </p><div class="variablelist"><table border="0"><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>. </td></tr><tr><td><span class="term"><i class="parameter"><tt>t</tt></i> :</span></td><td>the type of the elements. </td></tr><tr><td><span class="term"><i class="parameter"><tt>i</tt></i> :</span></td><td>the index of the element to return. </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>. </td></tr></tbody></table></div></div><hr/><div lang="en" class="refsect2"><a name="id3226818"/><h3><a name="g-array-set-size"/>g_array_set_size ()</h3><a class="indexterm" name="id3226829"/><pre class="programlisting"><a href="glib-Arrays.html#GArray">GArray</a>* g_array_set_size (
<a href="glib-Arrays.html#GArray">GArray</a> *array,
<a href="glib-Basic-Types.html#guint">guint</a> length);</pre><p> Sets the size of the array, expanding it if necessary.
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. </p><div class="variablelist"><table border="0"><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>. </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>. </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>. </td></tr></tbody></table></div></div><hr/><div lang="en" class="refsect2"><a name="id3226944"/><h3><a name="g-array-free"/>g_array_free ()</h3><a class="indexterm" name="id3226955"/><pre class="programlisting"><a href="glib-Basic-Types.html#gchar">gchar</a>* g_array_free (
<a href="glib-Arrays.html#GArray">GArray</a> *array,
<a href="glib-Basic-Types.html#gboolean">gboolean</a> free_segment);</pre><p> Frees the memory allocated for the
<a href="glib-Arrays.html#GArray"><span class="type">GArray</span></a>.
If
<i class="parameter"><tt>free_segment</tt></i> is
<tt class="literal">TRUE</tt> it frees the actual element data as well. </p><div class="variablelist"><table border="0"><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>. </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. </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> </td></tr></tbody></table></div></div></div></div><table width="100%" cellspacing="0" cellpadding="2" class="navigation" summary="Navigation footer"><tbody><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></tbody></table> </body></html>
(26-26/29)