add cx_array_default_reallocator

Wed, 24 Jan 2024 22:19:05 +0100

author
Mike Becker <universe@uap-core.de>
date
Wed, 24 Jan 2024 22:19:05 +0100
changeset 817
949908c97474
parent 816
425234b05dff
child 818
2be8fe3d5a2d

add cx_array_default_reallocator

CHANGELOG file | annotate | diff | comparison | revisions
src/array_list.c file | annotate | diff | comparison | revisions
src/cx/array_list.h file | annotate | diff | comparison | revisions
--- a/CHANGELOG	Mon Jan 22 19:34:38 2024 +0100
+++ b/CHANGELOG	Wed Jan 24 22:19:05 2024 +0100
@@ -1,5 +1,7 @@
 Version 3.1 - tbd.
 ------------------------
+ * adds tree.h
+ * adds cx_array_default_reallocator
  * adds cx_linked_list_find_node()
  * adds cxListFindRemove()
  * adds cxBufferReset()
--- a/src/array_list.c	Mon Jan 22 19:34:38 2024 +0100
+++ b/src/array_list.c	Wed Jan 24 22:19:05 2024 +0100
@@ -31,6 +31,21 @@
 #include <assert.h>
 #include <string.h>
 
+// Default array reallocator
+
+static void *cx_array_default_realloc(
+        void *array,
+        size_t capacity,
+        size_t elem_size,
+        __attribute__((__unused__)) struct cx_array_reallocator_s *alloc
+) {
+    return realloc(array, capacity * elem_size);
+}
+
+struct cx_array_reallocator_s cx_array_default_reallocator = {
+        cx_array_default_realloc, NULL, NULL, 0, 0
+};
+
 // LOW LEVEL ARRAY LIST FUNCTIONS
 
 enum cx_array_copy_result cx_array_copy(
--- a/src/cx/array_list.h	Mon Jan 22 19:34:38 2024 +0100
+++ b/src/cx/array_list.h	Wed Jan 24 22:19:05 2024 +0100
@@ -94,6 +94,11 @@
 };
 
 /**
+ * A default stdlib-based array reallocator.
+ */
+extern struct cx_array_reallocator_s cx_array_default_reallocator;
+
+/**
  * Return codes for cx_array_copy().
  */
 enum cx_array_copy_result {

mercurial