Function

GLibArraynew_take

since: 2.76

Declaration

GArray*
g_array_new_take (
  gpointer data,
  gsize len,
  gboolean clear,
  gsize element_size
)

Description

Creates a new GArray with data as array data, len as length and a reference count of 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().

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 len 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, or NULL for an empty array.

The length of the array is specified in the len argument.
len

Type: gsize

The number of elements in data.

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.