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
     1.1 --- a/CHANGELOG	Mon Jan 22 19:34:38 2024 +0100
     1.2 +++ b/CHANGELOG	Wed Jan 24 22:19:05 2024 +0100
     1.3 @@ -1,5 +1,7 @@
     1.4  Version 3.1 - tbd.
     1.5  ------------------------
     1.6 + * adds tree.h
     1.7 + * adds cx_array_default_reallocator
     1.8   * adds cx_linked_list_find_node()
     1.9   * adds cxListFindRemove()
    1.10   * adds cxBufferReset()
     2.1 --- a/src/array_list.c	Mon Jan 22 19:34:38 2024 +0100
     2.2 +++ b/src/array_list.c	Wed Jan 24 22:19:05 2024 +0100
     2.3 @@ -31,6 +31,21 @@
     2.4  #include <assert.h>
     2.5  #include <string.h>
     2.6  
     2.7 +// Default array reallocator
     2.8 +
     2.9 +static void *cx_array_default_realloc(
    2.10 +        void *array,
    2.11 +        size_t capacity,
    2.12 +        size_t elem_size,
    2.13 +        __attribute__((__unused__)) struct cx_array_reallocator_s *alloc
    2.14 +) {
    2.15 +    return realloc(array, capacity * elem_size);
    2.16 +}
    2.17 +
    2.18 +struct cx_array_reallocator_s cx_array_default_reallocator = {
    2.19 +        cx_array_default_realloc, NULL, NULL, 0, 0
    2.20 +};
    2.21 +
    2.22  // LOW LEVEL ARRAY LIST FUNCTIONS
    2.23  
    2.24  enum cx_array_copy_result cx_array_copy(
     3.1 --- a/src/cx/array_list.h	Mon Jan 22 19:34:38 2024 +0100
     3.2 +++ b/src/cx/array_list.h	Wed Jan 24 22:19:05 2024 +0100
     3.3 @@ -94,6 +94,11 @@
     3.4  };
     3.5  
     3.6  /**
     3.7 + * A default stdlib-based array reallocator.
     3.8 + */
     3.9 +extern struct cx_array_reallocator_s cx_array_default_reallocator;
    3.10 +
    3.11 +/**
    3.12   * Return codes for cx_array_copy().
    3.13   */
    3.14  enum cx_array_copy_result {

mercurial