Function

GLibArraynew_take_zero_terminated

since: 2.76

Declaration

GArray*
g_array_new_take_zero_terminated (
  gpointer data,
  gboolean clear,
  gsize element_size
)

Description

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

This avoids having to copy the data manually, when it can just be inherited. After this call, data belongs to the GArray and may no longer be modified by the caller. The memory of data has to be dynamically allocated and will eventually be freed with g_free().

The length is calculated by iterating through data until the first NULL element is found.

In case the elements need to be cleared when the array is freed, use g_array_set_clear_func() to set a GDestroyNotify function to perform such task.

Do not use it if data length or element_size are greater than G_MAXUINT. GArray stores the length of its data in #guint, which may be shorter than #gsize.

Available since: 2.76

This function is not directly available to language bindings.

Parameters

data

Type: An array of gpointer

An array of elements of element_size.

The array must be NULL-terminated.
clear

Type: gboolean

TRUE if GArray elements should be automatically cleared to 0 when they are allocated.

element_size

Type: gsize

The size of each element in bytes.

Return value

Type: An array of gpointer

A new GArray.

The caller of the function takes ownership of the data, and is responsible for freeing it.