src/cx/array_list.h

changeset 1084
0bcd71d2615a
parent 1066
8610f87a6b14
child 1089
865c84fef6b4
--- a/src/cx/array_list.h	Sat Jan 04 11:55:31 2025 +0100
+++ b/src/cx/array_list.h	Sat Jan 04 12:31:28 2025 +0100
@@ -192,13 +192,16 @@
  * This function checks if the \p capacity of the array is sufficient to hold
  * at least \p size plus \p elem_count elements. If not, a reallocation is
  * performed with the specified \p reallocator.
+ * You can create your own reallocator by hand or use the convenience function
+ * cx_array_reallocator().
  *
  * This function can be useful to replace subsequent calls to cx_array_copy()
  * with one single cx_array_reserve() and then - after guaranteeing a
  * sufficient capacity - use simple memmove() or memcpy().
  *
- * The \p width refers to the size and capacity. Both must have the same width.
- * Supported are 0, 8, 16, and 32, as well as 64 if running on a 64 bit
+ * The \p width in bytes refers to the size and capacity.
+ * Both must have the same width.
+ * Supported are 0, 1, 2, and 4, as well as 8 if running on a 64 bit
  * architecture. If set to zero, the native word width is used.
  *
  * @param array a pointer to the target array
@@ -209,6 +212,7 @@
  * @param elem_count the number of expected additional elements
  * @param reallocator the array reallocator to use
  * @return zero on success, non-zero on failure
+ * @see cx_array_reallocator()
  */
 cx_attr_nonnull
 int cx_array_reserve(
@@ -231,9 +235,12 @@
  *
  * If the \p capacity is also insufficient to hold the new data, a reallocation
  * attempt is made with the specified \p reallocator.
+ * You can create your own reallocator by hand or use the convenience function
+ * cx_array_reallocator().
  *
- * The \p width refers to the size and capacity. Both must have the same width.
- * Supported are 0, 8, 16, and 32, as well as 64 if running on a 64 bit
+ * The \p width in bytes refers to the size and capacity.
+ * Both must have the same width.
+ * Supported are 0, 1, 2, and 4, as well as 8 if running on a 64 bit
  * architecture. If set to zero, the native word width is used.
  *
  * @param target a pointer to the target array
@@ -246,6 +253,7 @@
  * @param elem_count the number of elements to copy
  * @param reallocator the array reallocator to use
  * @return zero on success, non-zero on failure
+ * @see cx_array_reallocator()
  */
 cx_attr_nonnull
 int cx_array_copy(
@@ -275,7 +283,7 @@
  */
 #define cx_array_simple_copy_a(reallocator, array, index, src, count) \
     cx_array_copy((void**)&(array), &(array##_size), &(array##_capacity), \
-        8*sizeof(array##_size), index, src, sizeof((array)[0]), count, \
+        sizeof(array##_size), index, src, sizeof((array)[0]), count, \
         reallocator)
 
 /**
@@ -307,7 +315,7 @@
  */
 #define cx_array_simple_reserve_a(reallocator, array, count) \
     cx_array_reserve((void**)&(array), &(array##_size), &(array##_capacity), \
-        8*sizeof(array##_size), sizeof((array)[0]), count, \
+        sizeof(array##_size), sizeof((array)[0]), count, \
         reallocator)
 
 /**
@@ -343,7 +351,7 @@
  * @return zero on success, non-zero on failure
  */
 #define cx_array_add(target, size, capacity, elem_size, elem, reallocator) \
-    cx_array_copy((void**)(target), size, capacity, 8*sizeof(*(size)), \
+    cx_array_copy((void**)(target), size, capacity, sizeof(*(size)), \
     *(size), elem, elem_size, 1, reallocator)
 
 /**

mercurial