GLib.Array
Description: Reference for GLib.Array

### Struct

# GLibArray

since: 2.0

#### Description

    struct GArray {
      gchar* data;
      guint len;
    }

Contains the public fields of a GArray.

###### Structure members

`data`

  A pointer to the element data. The data may be moved as elements are added to the `GArray`.

`len`

  The number of elements in the `GArray` not including the possible terminating zero element.

Available since: 2.0

#### Functions

###### g_array_append_vals

Adds `len` elements onto the end of the array.

since: 2.0

###### g_array_binary_search

Checks whether `target` exists in `array` by performing a binary search based on the given comparison function `compare_func` which get pointers to items as arguments. If the element is found, `TRUE` is returned and the element’s index is returned in `out_match_index` (if non-`NULL`). Otherwise, `FALSE` is returned and `out_match_index` is undefined. If `target` exists multiple times in `array`, the index of the first instance is returned. This search is using a binary search, so the `array` must absolutely be sorted to return a correct result (if not, the function may produce false-negative).

since: 2.62

###### g_array_copy

Create a shallow copy of a `GArray`. If the array elements consist of pointers to data, the pointers are copied but the actual data is not.

since: 2.62

###### g_array_free

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

since: 2.0

###### g_array_get_element_size

Gets the size of the elements in `array`.

since: 2.22

###### g_array_insert_vals

Inserts `len` elements into a `GArray` at the given index.

since: 2.0

###### g_array_new

Creates a new `GArray` with a reference count of 1.

since: 2.0

###### g_array_new_take

Creates a new `GArray` with `data` as array data, `len` as length and a reference count of 1.

since: 2.76

###### g_array_new_take_zero_terminated

Creates a new `GArray` with `data` as array data, computing the length of it and setting the reference count to 1.

since: 2.76

###### g_array_prepend_vals

Adds `len` elements onto the start of the array.

since: 2.0

###### g_array_ref

Atomically increments the reference count of `array` by one. This function is thread-safe and may be called from any thread.

since: 2.22

###### g_array_remove_index

Removes the element at the given index from a `GArray`. The following elements are moved down one place.

since: 2.0

###### g_array_remove_index_fast

Removes the element at the given index from a `GArray`. The last element in the array is used to fill in the space, so this function does not preserve the order of the `GArray`. But it is faster than g_array_remove_index().

since: 2.0

###### g_array_remove_range

Removes the given number of elements starting at the given index from a `GArray`. The following elements are moved to close the gap.

since: 2.4

###### g_array_set_clear_func

Sets a function to clear an element of `array`.

since: 2.32

###### g_array_set_size

Sets the size of the array, expanding it if necessary. If the array was created with `clear_` set to `TRUE`, the new elements are set to 0.

since: 2.0

###### g_array_sized_new

Creates a new `GArray` with `reserved_size` elements preallocated and a reference count of 1. 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.

since: 2.0

###### g_array_sort

Sorts a `GArray` using `compare_func` which should be a qsort()-style comparison function (returns less than zero for first arg is less than second arg, zero for equal, greater zero if first arg is greater than second arg).

since: 2.0

###### g_array_sort_with_data

Like g_array_sort(), but the comparison function receives an extra user data argument.

since: 2.0

###### g_array_steal

Frees the data in the array and resets the size to zero, while the underlying array is preserved for use elsewhere and returned to the caller.

since: 2.64

###### g_array_unref

Atomically decrements the reference count of `array` by one. If the reference count drops to 0, all memory allocated by the array is released. This function is thread-safe and may be called from any thread.

since: 2.22