[glib] Add g_ptr_array_new_full
- From: Xavier Claessens <xclaesse src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] Add g_ptr_array_new_full
- Date: Fri, 22 Jul 2011 08:20:00 +0000 (UTC)
commit eec69a75eeddc9e298f218e5b3e4bb5084adfe6f
Author: Xavier Claessens <xclaesse gmail com>
Date: Thu Jul 14 10:51:06 2011 +0200
Add g_ptr_array_new_full
Fixes bug #654450
docs/reference/glib/glib-sections.txt | 1 +
glib/garray.c | 28 ++++++++++++++++++++++++++++
glib/garray.h | 2 ++
3 files changed, 31 insertions(+), 0 deletions(-)
---
diff --git a/docs/reference/glib/glib-sections.txt b/docs/reference/glib/glib-sections.txt
index e765ef4..853c793 100644
--- a/docs/reference/glib/glib-sections.txt
+++ b/docs/reference/glib/glib-sections.txt
@@ -2380,6 +2380,7 @@ GPtrArray
g_ptr_array_new
g_ptr_array_sized_new
g_ptr_array_new_with_free_func
+g_ptr_array_new_full
g_ptr_array_set_free_func
g_ptr_array_ref
g_ptr_array_unref
diff --git a/glib/garray.c b/glib/garray.c
index fa6160b..07149b0 100644
--- a/glib/garray.c
+++ b/glib/garray.c
@@ -837,6 +837,34 @@ g_ptr_array_new_with_free_func (GDestroyNotify element_free_func)
}
/**
+ * g_ptr_array_new_full:
+ * @reserved_size: number of pointers preallocated.
+ * @element_free_func: A function to free elements with destroy @array or %NULL.
+ *
+ * Creates a new #GPtrArray with @reserved_size pointers preallocated
+ * and a reference count of 1. This avoids frequent reallocation, if
+ * you are going to add many pointers to the array. Note however that
+ * the size of the array is still 0. It also set @element_free_func
+ * for freeing each element when the array is destroyed either via
+ * g_ptr_array_unref(), when g_ptr_array_free() is called with @free_segment
+ * set to %TRUE or when removing elements.
+ *
+ * Returns: A new #GPtrArray.
+ *
+ * Since: 2.30
+ **/
+GPtrArray *
+g_ptr_array_new_full (guint reserved_size,
+ GDestroyNotify element_free_func)
+{
+ GPtrArray *array;
+
+ array = g_ptr_array_sized_new (reserved_size);
+ g_ptr_array_set_free_func (array, element_free_func);
+ return array;
+}
+
+/**
* g_ptr_array_set_free_func:
* @array: A #GPtrArray.
* @element_free_func: A function to free elements with destroy @array or %NULL.
diff --git a/glib/garray.h b/glib/garray.h
index 6bc51f7..8221806 100644
--- a/glib/garray.h
+++ b/glib/garray.h
@@ -112,6 +112,8 @@ void g_array_sort_with_data (GArray *array,
GPtrArray* g_ptr_array_new (void);
GPtrArray* g_ptr_array_new_with_free_func (GDestroyNotify element_free_func);
GPtrArray* g_ptr_array_sized_new (guint reserved_size);
+GPtrArray* g_ptr_array_new_full (guint reserved_size,
+ GDestroyNotify element_free_func);
gpointer* g_ptr_array_free (GPtrArray *array,
gboolean free_seg);
GPtrArray* g_ptr_array_ref (GPtrArray *array);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]