Blame docs/reference/glib/html/glib-Pointer-Arrays.html

Packit ae235b
Packit ae235b
<html>
Packit ae235b
<head>
Packit ae235b
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
Packit ae235b
<title>Pointer Arrays: GLib Reference Manual</title>
Packit ae235b
<meta name="generator" content="DocBook XSL Stylesheets Vsnapshot">
Packit ae235b
<link rel="home" href="index.html" title="GLib Reference Manual">
Packit ae235b
<link rel="up" href="glib-data-types.html" title="GLib Data Types">
Packit ae235b
<link rel="prev" href="glib-Arrays.html" title="Arrays">
Packit ae235b
<link rel="next" href="glib-Byte-Arrays.html" title="Byte Arrays">
Packit ae235b
<meta name="generator" content="GTK-Doc V1.27 (XML mode)">
Packit ae235b
<link rel="stylesheet" href="style.css" type="text/css">
Packit ae235b
</head>
Packit ae235b
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
Packit ae235b
Packit ae235b
Packit ae235b
Top  | 
Packit ae235b
                  Description
Packit ae235b
Packit ae235b
Home
Packit ae235b
Up
Packit ae235b
Prev
Packit ae235b
Next
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Pointer Arrays

Packit ae235b

Pointer Arrays — arrays of pointers to any type of data, which

Packit ae235b
    grow automatically as new elements are added

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Functions

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
GPtrArray *
Packit ae235b
Packit ae235b
Packit ae235b
g_ptr_array_new ()
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
GPtrArray *
Packit ae235b
Packit ae235b
Packit ae235b
g_ptr_array_sized_new ()
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
GPtrArray *
Packit ae235b
Packit ae235b
Packit ae235b
g_ptr_array_new_with_free_func ()
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
GPtrArray *
Packit ae235b
Packit ae235b
Packit ae235b
g_ptr_array_new_full ()
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
void
Packit ae235b
Packit ae235b
Packit ae235b
g_ptr_array_set_free_func ()
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
GPtrArray *
Packit ae235b
Packit ae235b
Packit ae235b
g_ptr_array_ref ()
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
void
Packit ae235b
Packit ae235b
Packit ae235b
g_ptr_array_unref ()
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
void
Packit ae235b
Packit ae235b
Packit ae235b
g_ptr_array_add ()
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
void
Packit ae235b
Packit ae235b
Packit ae235b
g_ptr_array_insert ()
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
gboolean
Packit ae235b
Packit ae235b
Packit ae235b
g_ptr_array_remove ()
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
gpointer
Packit ae235b
Packit ae235b
Packit ae235b
g_ptr_array_remove_index ()
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
gboolean
Packit ae235b
Packit ae235b
Packit ae235b
g_ptr_array_remove_fast ()
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
gpointer
Packit ae235b
Packit ae235b
Packit ae235b
g_ptr_array_remove_index_fast ()
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
GPtrArray *
Packit ae235b
Packit ae235b
Packit ae235b
g_ptr_array_remove_range ()
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
void
Packit ae235b
Packit ae235b
Packit ae235b
g_ptr_array_sort ()
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
void
Packit ae235b
Packit ae235b
Packit ae235b
g_ptr_array_sort_with_data ()
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
void
Packit ae235b
Packit ae235b
Packit ae235b
g_ptr_array_set_size ()
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
#define
Packit ae235b
Packit ae235b
g_ptr_array_index()
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
gpointer *
Packit ae235b
Packit ae235b
Packit ae235b
g_ptr_array_free ()
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
void
Packit ae235b
Packit ae235b
Packit ae235b
g_ptr_array_foreach ()
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
gboolean
Packit ae235b
Packit ae235b
Packit ae235b
g_ptr_array_find ()
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
gboolean
Packit ae235b
Packit ae235b
Packit ae235b
g_ptr_array_find_with_equal_func ()
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Types and Values

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
struct
Packit ae235b
GPtrArray
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Includes

Packit ae235b
#include <gmodule.h>
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Description

Packit ae235b

Pointer Arrays are similar to Arrays but are used only for storing

Packit ae235b
pointers.

Packit ae235b

If you remove elements from the array, elements at the end of the

Packit ae235b
array are moved into the space previously occupied by the removed
Packit ae235b
element. This means that you should not rely on the index of particular
Packit ae235b
elements remaining the same. You should also be careful when deleting
Packit ae235b
elements while iterating over the array.

Packit ae235b

To create a pointer array, use g_ptr_array_new().

Packit ae235b

To add elements to a pointer array, use g_ptr_array_add().

Packit ae235b

To remove elements from a pointer array, use g_ptr_array_remove(),

Packit ae235b
g_ptr_array_remove_index() or g_ptr_array_remove_index_fast().

Packit ae235b

To access an element of a pointer array, use g_ptr_array_index().

Packit ae235b

To set the size of a pointer array, use g_ptr_array_set_size().

Packit ae235b

To free a pointer array, use g_ptr_array_free().

Packit ae235b

An example using a GPtrArray:

Packit ae235b
Packit ae235b
  
Packit ae235b
    
Packit ae235b
      
Packit ae235b
        
1
Packit ae235b
2
Packit ae235b
3
Packit ae235b
4
Packit ae235b
5
Packit ae235b
6
Packit ae235b
7
Packit ae235b
8
Packit ae235b
9
Packit ae235b
10
Packit ae235b
11
Packit ae235b
12
Packit ae235b
13
Packit ae235b
14
Packit ae235b
15
Packit ae235b
        
GPtrArray *array;
Packit ae235b
gchar *string1 = "one";
Packit ae235b
gchar *string2 = "two";
Packit ae235b
gchar *string3 = "three";
Packit ae235b
Packit ae235b
array = g_ptr_array_new ();
Packit ae235b
g_ptr_array_add (array, (gpointer) string1);
Packit ae235b
g_ptr_array_add (array, (gpointer) string2);
Packit ae235b
g_ptr_array_add (array, (gpointer) string3);
Packit ae235b
Packit ae235b
if (g_ptr_array_index (array, 0) != (gpointer) string1)
Packit ae235b
  g_print ("ERROR: got %p instead of %p\n",
Packit ae235b
           g_ptr_array_index (array, 0), string1);
Packit ae235b
Packit ae235b
g_ptr_array_free (array, TRUE);
Packit ae235b
      
Packit ae235b
    
Packit ae235b
  
Packit ae235b
Packit ae235b
Packit ae235b

Packit ae235b
Packit ae235b
Packit ae235b

Functions

Packit ae235b
Packit ae235b

g_ptr_array_new ()

Packit ae235b
GPtrArray *
Packit ae235b
g_ptr_array_new (void);
Packit ae235b

Creates a new GPtrArray with a reference count of 1.

Packit ae235b
Packit ae235b

Returns

Packit ae235b

the new GPtrArray

Packit ae235b
Packit ae235b
Packit ae235b

Packit ae235b
Packit ae235b

g_ptr_array_sized_new ()

Packit ae235b
GPtrArray *
Packit ae235b
g_ptr_array_sized_new (guint reserved_size);
Packit ae235b

Creates a new GPtrArray with reserved_size

Packit ae235b
 pointers preallocated
Packit ae235b
and a reference count of 1. This avoids frequent reallocation, if
Packit ae235b
you are going to add many pointers to the array. Note however that
Packit ae235b
the size of the array is still 0.

Packit ae235b
Packit ae235b

Parameters

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

reserved_size

Packit ae235b

number of pointers preallocated

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Returns

Packit ae235b

the new GPtrArray

Packit ae235b
Packit ae235b
Packit ae235b

Packit ae235b
Packit ae235b

g_ptr_array_new_with_free_func ()

Packit ae235b
GPtrArray *
Packit ae235b
g_ptr_array_new_with_free_func (GDestroyNotify element_free_func);
Packit ae235b

Creates a new GPtrArray with a reference count of 1 and use

Packit ae235b
element_free_func
Packit ae235b
 for freeing each element when the array is destroyed
Packit ae235b
either via g_ptr_array_unref(), when g_ptr_array_free() is called with
Packit ae235b
free_segment
Packit ae235b
 set to TRUE or when removing elements.

Packit ae235b
Packit ae235b

Parameters

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

element_free_func

Packit ae235b

A function to free elements with

Packit ae235b
destroy array
Packit ae235b
or NULL. 

Packit ae235b
[nullable]
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Returns

Packit ae235b

A new GPtrArray

Packit ae235b
Packit ae235b

Since: 2.22

Packit ae235b
Packit ae235b

Packit ae235b
Packit ae235b

g_ptr_array_new_full ()

Packit ae235b
GPtrArray *
Packit ae235b
g_ptr_array_new_full (guint reserved_size,
Packit ae235b
                      GDestroyNotify element_free_func);
Packit ae235b

Creates a new GPtrArray with reserved_size

Packit ae235b
 pointers preallocated
Packit ae235b
and a reference count of 1. This avoids frequent reallocation, if
Packit ae235b
you are going to add many pointers to the array. Note however that
Packit ae235b
the size of the array is still 0. It also set element_free_func
Packit ae235b
Packit ae235b
for freeing each element when the array is destroyed either via
Packit ae235b
g_ptr_array_unref(), when g_ptr_array_free() is called with
Packit ae235b
free_segment
Packit ae235b
 set to TRUE or when removing elements.

Packit ae235b
Packit ae235b

Parameters

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

reserved_size

Packit ae235b

number of pointers preallocated

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b

element_free_func

Packit ae235b

A function to free elements with

Packit ae235b
destroy array
Packit ae235b
or NULL. 

Packit ae235b
[nullable]
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Returns

Packit ae235b

A new GPtrArray

Packit ae235b
Packit ae235b

Since: 2.30

Packit ae235b
Packit ae235b

Packit ae235b
Packit ae235b

g_ptr_array_set_free_func ()

Packit ae235b
void
Packit ae235b
g_ptr_array_set_free_func (GPtrArray *array,
Packit ae235b
                           GDestroyNotify element_free_func);
Packit ae235b

Sets a function for freeing each element when array

Packit ae235b
 is destroyed
Packit ae235b
either via g_ptr_array_unref(), when g_ptr_array_free() is called
Packit ae235b
with free_segment
Packit ae235b
 set to TRUE or when removing elements.

Packit ae235b
Packit ae235b

Parameters

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

array

Packit ae235b

A GPtrArray

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b

element_free_func

Packit ae235b

A function to free elements with

Packit ae235b
destroy array
Packit ae235b
or NULL. 

Packit ae235b
[nullable]
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Since: 2.22

Packit ae235b
Packit ae235b

Packit ae235b
Packit ae235b

g_ptr_array_ref ()

Packit ae235b
GPtrArray *
Packit ae235b
g_ptr_array_ref (GPtrArray *array);
Packit ae235b

Atomically increments the reference count of array

Packit ae235b
 by one.
Packit ae235b
This function is thread-safe and may be called from any thread.

Packit ae235b
Packit ae235b

Parameters

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

array

Packit ae235b

a GPtrArray

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Returns

Packit ae235b

The passed in GPtrArray

Packit ae235b
Packit ae235b

Since: 2.22

Packit ae235b
Packit ae235b

Packit ae235b
Packit ae235b

g_ptr_array_unref ()

Packit ae235b
void
Packit ae235b
g_ptr_array_unref (GPtrArray *array);
Packit ae235b

Atomically decrements the reference count of array

Packit ae235b
 by one. If the
Packit ae235b
reference count drops to 0, the effect is the same as calling
Packit ae235b
g_ptr_array_free() with free_segment
Packit ae235b
 set to TRUE. This function
Packit ae235b
is thread-safe and may be called from any thread.

Packit ae235b
Packit ae235b

Parameters

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

array

Packit ae235b

A GPtrArray

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Since: 2.22

Packit ae235b
Packit ae235b

Packit ae235b
Packit ae235b

g_ptr_array_add ()

Packit ae235b
void
Packit ae235b
g_ptr_array_add (GPtrArray *array,
Packit ae235b
                 gpointer data);
Packit ae235b

Adds a pointer to the end of the pointer array. The array will grow

Packit ae235b
in size automatically if necessary.

Packit ae235b
Packit ae235b

Parameters

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

array

Packit ae235b

a GPtrArray

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b

data

Packit ae235b

the pointer to add

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Packit ae235b
Packit ae235b

g_ptr_array_insert ()

Packit ae235b
void
Packit ae235b
g_ptr_array_insert (GPtrArray *array,
Packit ae235b
                    gint index_,
Packit ae235b
                    gpointer data);
Packit ae235b

Inserts an element into the pointer array at the given index. The

Packit ae235b
array will grow in size automatically if necessary.

Packit ae235b
Packit ae235b

Parameters

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

array

Packit ae235b

a GPtrArray

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b

index_

Packit ae235b

the index to place the new element at, or -1 to append

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b

data

Packit ae235b

the pointer to add.

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Since: 2.40

Packit ae235b
Packit ae235b

Packit ae235b
Packit ae235b

g_ptr_array_remove ()

Packit ae235b
gboolean
Packit ae235b
g_ptr_array_remove (GPtrArray *array,
Packit ae235b
                    gpointer data);
Packit ae235b

Removes the first occurrence of the given pointer from the pointer

Packit ae235b
array. The following elements are moved down one place. If array
Packit ae235b
Packit ae235b
has a non-NULL GDestroyNotify function it is called for the
Packit ae235b
removed element.

Packit ae235b

It returns TRUE if the pointer was removed, or FALSE if the

Packit ae235b
pointer was not found.

Packit ae235b
Packit ae235b

Parameters

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

array

Packit ae235b

a GPtrArray

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b

data

Packit ae235b

the pointer to remove

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Returns

Packit ae235b

TRUE if the pointer is removed, FALSE if the pointer

Packit ae235b
is not found in the array

Packit ae235b
Packit ae235b
Packit ae235b

Packit ae235b
Packit ae235b

g_ptr_array_remove_index ()

Packit ae235b
gpointer
Packit ae235b
g_ptr_array_remove_index (GPtrArray *array,
Packit ae235b
                          guint index_);
Packit ae235b

Removes the pointer at the given index from the pointer array.

Packit ae235b
The following elements are moved down one place. If array
Packit ae235b
 has
Packit ae235b
a non-NULL GDestroyNotify function it is called for the removed
Packit ae235b
element.

Packit ae235b
Packit ae235b

Parameters

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

array

Packit ae235b

a GPtrArray

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b

index_

Packit ae235b

the index of the pointer to remove

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Returns

Packit ae235b

the pointer which was removed

Packit ae235b
Packit ae235b
Packit ae235b

Packit ae235b
Packit ae235b

g_ptr_array_remove_fast ()

Packit ae235b
gboolean
Packit ae235b
g_ptr_array_remove_fast (GPtrArray *array,
Packit ae235b
                         gpointer data);
Packit ae235b

Removes the first occurrence of the given pointer from the pointer

Packit ae235b
array. The last element in the array is used to fill in the space,
Packit ae235b
so this function does not preserve the order of the array. But it
Packit ae235b
is faster than g_ptr_array_remove(). If array
Packit ae235b
 has a non-NULL
Packit ae235b
GDestroyNotify function it is called for the removed element.

Packit ae235b

It returns TRUE if the pointer was removed, or FALSE if the

Packit ae235b
pointer was not found.

Packit ae235b
Packit ae235b

Parameters

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

array

Packit ae235b

a GPtrArray

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b

data

Packit ae235b

the pointer to remove

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Returns

Packit ae235b

TRUE if the pointer was found in the array

Packit ae235b
Packit ae235b
Packit ae235b

Packit ae235b
Packit ae235b

g_ptr_array_remove_index_fast ()

Packit ae235b
gpointer
Packit ae235b
g_ptr_array_remove_index_fast (GPtrArray *array,
Packit ae235b
                               guint index_);
Packit ae235b

Removes the pointer at the given index from the pointer array.

Packit ae235b
The last element in the array is used to fill in the space, so
Packit ae235b
this function does not preserve the order of the array. But it
Packit ae235b
is faster than g_ptr_array_remove_index(). If array
Packit ae235b
 has a non-NULL
Packit ae235b
GDestroyNotify function it is called for the removed element.

Packit ae235b
Packit ae235b

Parameters

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

array

Packit ae235b

a GPtrArray

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b

index_

Packit ae235b

the index of the pointer to remove

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Returns

Packit ae235b

the pointer which was removed

Packit ae235b
Packit ae235b
Packit ae235b

Packit ae235b
Packit ae235b

g_ptr_array_remove_range ()

Packit ae235b
GPtrArray *
Packit ae235b
g_ptr_array_remove_range (GPtrArray *array,
Packit ae235b
                          guint index_,
Packit ae235b
                          guint length);
Packit ae235b

Removes the given number of pointers starting at the given index

Packit ae235b
from a GPtrArray. The following elements are moved to close the
Packit ae235b
gap. If array
Packit ae235b
 has a non-NULL GDestroyNotify function it is
Packit ae235b
called for the removed elements.

Packit ae235b
Packit ae235b

Parameters

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

array

Packit ae235b

a GPtrArray

Packit ae235b

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b

index_

Packit ae235b

the index of the first pointer to remove

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b

length

Packit ae235b

the number of pointers to remove

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Returns

Packit ae235b

the array

Packit ae235b

Packit ae235b
Packit ae235b

Since: 2.4

Packit ae235b
Packit ae235b

Packit ae235b
Packit ae235b

g_ptr_array_sort ()

Packit ae235b
void
Packit ae235b
g_ptr_array_sort (GPtrArray *array,
Packit ae235b
                  GCompareFunc compare_func);
Packit ae235b

Sorts the array, using compare_func

Packit ae235b
 which should be a qsort()-style
Packit ae235b
comparison function (returns less than zero for first arg is less
Packit ae235b
than second arg, zero for equal, greater than zero if irst arg is
Packit ae235b
greater than second arg).

Packit ae235b

Note that the comparison function for g_ptr_array_sort() doesn't

Packit ae235b
take the pointers from the array as arguments, it takes pointers to
Packit ae235b
the pointers in the array.

Packit ae235b

This is guaranteed to be a stable sort since version 2.32.

Packit ae235b
Packit ae235b

Parameters

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

array

Packit ae235b

a GPtrArray

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b

compare_func

Packit ae235b

comparison function

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Packit ae235b
Packit ae235b

g_ptr_array_sort_with_data ()

Packit ae235b
void
Packit ae235b
g_ptr_array_sort_with_data (GPtrArray *array,
Packit ae235b
                            GCompareDataFunc compare_func,
Packit ae235b
                            gpointer user_data);
Packit ae235b

Like g_ptr_array_sort(), but the comparison function has an extra

Packit ae235b
user data argument.

Packit ae235b

Note that the comparison function for g_ptr_array_sort_with_data()

Packit ae235b
doesn't take the pointers from the array as arguments, it takes
Packit ae235b
pointers to the pointers in the array.

Packit ae235b

This is guaranteed to be a stable sort since version 2.32.

Packit ae235b
Packit ae235b

Parameters

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

array

Packit ae235b

a GPtrArray

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b

compare_func

Packit ae235b

comparison function

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b

user_data

Packit ae235b

data to pass to compare_func

Packit ae235b

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Packit ae235b
Packit ae235b

g_ptr_array_set_size ()

Packit ae235b
void
Packit ae235b
g_ptr_array_set_size (GPtrArray *array,
Packit ae235b
                      gint length);
Packit ae235b

Sets the size of the array. When making the array larger,

Packit ae235b
newly-added elements will be set to NULL. When making it smaller,
Packit ae235b
if array
Packit ae235b
 has a non-NULL GDestroyNotify function then it will be
Packit ae235b
called for the removed elements.

Packit ae235b
Packit ae235b

Parameters

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

array

Packit ae235b

a GPtrArray

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b

length

Packit ae235b

the new length of the pointer array

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Packit ae235b
Packit ae235b

g_ptr_array_index()

Packit ae235b
#define             g_ptr_array_index(array,index_)
Packit ae235b

Returns the pointer at the given index of the pointer array.

Packit ae235b

This does not perform bounds checking on the given index_

Packit ae235b
,
Packit ae235b
so you are responsible for checking it against the array length.

Packit ae235b
Packit ae235b

Parameters

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

array

Packit ae235b

a GPtrArray

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b

index_

Packit ae235b

the index of the pointer to return

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Returns

Packit ae235b

the pointer at the given index

Packit ae235b
Packit ae235b
Packit ae235b

Packit ae235b
Packit ae235b

g_ptr_array_free ()

Packit ae235b
gpointer *
Packit ae235b
g_ptr_array_free (GPtrArray *array,
Packit ae235b
                  gboolean free_seg);
Packit ae235b

Frees the memory allocated for the GPtrArray. If free_seg

Packit ae235b
 is TRUE
Packit ae235b
it frees the memory block holding the elements as well. Pass FALSE
Packit ae235b
if you want to free the GPtrArray wrapper but preserve the
Packit ae235b
underlying array for use elsewhere. If the reference count of array
Packit ae235b
Packit ae235b
is greater than one, the GPtrArray wrapper is preserved but the
Packit ae235b
size of array
Packit ae235b
 will be set to zero.

Packit ae235b

If array contents point to dynamically-allocated memory, they should

Packit ae235b
be freed separately if free_seg
Packit ae235b
 is TRUE and no GDestroyNotify
Packit ae235b
function has been set for array
Packit ae235b
.

Packit ae235b

This function is not thread-safe. If using a GPtrArray from multiple

Packit ae235b
threads, use only the atomic g_ptr_array_ref() and g_ptr_array_unref()
Packit ae235b
functions.

Packit ae235b
Packit ae235b

Parameters

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

array

Packit ae235b

a GPtrArray

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b

free_seg

Packit ae235b

if TRUE the actual pointer array is freed as well

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Returns

Packit ae235b

the pointer array if free_seg

Packit ae235b
is FALSE, otherwise NULL.
Packit ae235b
The pointer array should be freed using g_free().

Packit ae235b
Packit ae235b
Packit ae235b

Packit ae235b
Packit ae235b

g_ptr_array_foreach ()

Packit ae235b
void
Packit ae235b
g_ptr_array_foreach (GPtrArray *array,
Packit ae235b
                     GFunc func,
Packit ae235b
                     gpointer user_data);
Packit ae235b

Calls a function for each element of a GPtrArray. func

Packit ae235b
 must not
Packit ae235b
add elements to or remove elements from the array.

Packit ae235b
Packit ae235b

Parameters

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

array

Packit ae235b

a GPtrArray

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b

func

Packit ae235b

the function to call for each array element

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b

user_data

Packit ae235b

user data to pass to the function

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Since: 2.4

Packit ae235b
Packit ae235b

Packit ae235b
Packit ae235b

g_ptr_array_find ()

Packit ae235b
gboolean
Packit ae235b
g_ptr_array_find (GPtrArray *haystack,
Packit ae235b
                  gconstpointer needle,
Packit ae235b
                  guint *index_);
Packit ae235b

Checks whether needle

Packit ae235b
 exists in haystack
Packit ae235b
. If the element is found, TRUE is
Packit ae235b
returned and the element’s index is returned in index_
Packit ae235b
 (if non-NULL).
Packit ae235b
Otherwise, FALSE is returned and index_
Packit ae235b
 is undefined. If needle
Packit ae235b
 exists
Packit ae235b
multiple times in haystack
Packit ae235b
, the index of the first instance is returned.

Packit ae235b

This does pointer comparisons only. If you want to use more complex equality

Packit ae235b
checks, such as string comparisons, use g_ptr_array_find_with_equal_func().

Packit ae235b

[skip]

Packit ae235b
Packit ae235b

Parameters

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

haystack

Packit ae235b

pointer array to be searched

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b

needle

Packit ae235b

pointer to look for

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b

index_

Packit ae235b

return location for the index of

Packit ae235b
the element, if found. 

Packit ae235b
[optional][out caller-allocates]
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Returns

Packit ae235b

TRUE if needle

Packit ae235b
is one of the elements of haystack
Packit ae235b

Packit ae235b
Packit ae235b

Since: 2.54

Packit ae235b
Packit ae235b

Packit ae235b
Packit ae235b

g_ptr_array_find_with_equal_func ()

Packit ae235b
gboolean
Packit ae235b
g_ptr_array_find_with_equal_func (GPtrArray *haystack,
Packit ae235b
                                  gconstpointer needle,
Packit ae235b
                                  GEqualFunc equal_func,
Packit ae235b
                                  guint *index_);
Packit ae235b

Checks whether needle

Packit ae235b
 exists in haystack
Packit ae235b
, using the given equal_func
Packit ae235b
.
Packit ae235b
If the element is found, TRUE is returned and the element’s index is
Packit ae235b
returned in index_
Packit ae235b
 (if non-NULL). Otherwise, FALSE is returned and index_
Packit ae235b
Packit ae235b
is undefined. If needle
Packit ae235b
 exists multiple times in haystack
Packit ae235b
, the index of
Packit ae235b
the first instance is returned.

Packit ae235b

equal_func

Packit ae235b
 is called with the element from the array as its first parameter,
Packit ae235b
and needle
Packit ae235b
 as its second parameter. If equal_func
Packit ae235b
 is NULL, pointer
Packit ae235b
equality is used.

Packit ae235b

[skip]

Packit ae235b
Packit ae235b

Parameters

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

haystack

Packit ae235b

pointer array to be searched

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b

needle

Packit ae235b

pointer to look for

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b

equal_func

Packit ae235b

the function to call for each element, which should

Packit ae235b
return TRUE when the desired element is found; or NULL to use pointer
Packit ae235b
equality. 

Packit ae235b
[nullable]
Packit ae235b
Packit ae235b
Packit ae235b

index_

Packit ae235b

return location for the index of

Packit ae235b
the element, if found. 

Packit ae235b
[optional][out caller-allocates]
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Returns

Packit ae235b

TRUE if needle

Packit ae235b
is one of the elements of haystack
Packit ae235b

Packit ae235b
Packit ae235b

Since: 2.54

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Types and Values

Packit ae235b
Packit ae235b

struct GPtrArray

Packit ae235b
struct GPtrArray {
Packit ae235b
  gpointer *pdata;
Packit ae235b
  guint	    len;
Packit ae235b
};
Packit ae235b
Packit ae235b

Contains the public fields of a pointer array.

Packit ae235b
Packit ae235b

Members

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

gpointer *pdata;

Packit ae235b

points to the array of pointers, which may be moved when the

Packit ae235b
array grows

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b

guint len;

Packit ae235b

number of pointers in the array

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Generated by GTK-Doc V1.27
Packit ae235b
</body>
Packit ae235b
</html>