src/ucx/allocator.c

changeset 582
82b60a8dd55c
parent 579
e10457d74fe1
child 621
956c03c25edd
--- a/src/ucx/allocator.c	Mon May 26 21:02:30 2025 +0200
+++ b/src/ucx/allocator.c	Mon May 26 21:06:17 2025 +0200
@@ -29,6 +29,7 @@
 #include "cx/allocator.h"
 
 #include <errno.h>
+#include <string.h>
 
 static void *cx_malloc_stdlib(
         cx_attr_unused void *d,
@@ -60,18 +61,19 @@
     free(mem);
 }
 
-static cx_allocator_class cx_default_allocator_class = {
+static cx_allocator_class cx_stdlib_allocator_class = {
         cx_malloc_stdlib,
         cx_realloc_stdlib,
         cx_calloc_stdlib,
         cx_free_stdlib
 };
 
-struct cx_allocator_s cx_default_allocator = {
-        &cx_default_allocator_class,
+struct cx_allocator_s cx_stdlib_allocator = {
+        &cx_stdlib_allocator_class,
         NULL
 };
-const CxAllocator * const cxDefaultAllocator = &cx_default_allocator;
+const CxAllocator * const cxStdlibAllocator = &cx_stdlib_allocator;
+const CxAllocator * cxDefaultAllocator = cxStdlibAllocator;
 
 int cx_reallocate_(
         void **mem,
@@ -115,6 +117,17 @@
     return allocator->cl->malloc(allocator->data, n);
 }
 
+void *cxZalloc(
+        const CxAllocator *allocator,
+        size_t n
+) {
+    void *mem = allocator->cl->malloc(allocator->data, n);
+    if (mem != NULL) {
+        memset(mem, 0, n);
+    }
+    return mem;
+}
+
 void *cxRealloc(
         const CxAllocator *allocator,
         void *mem,

mercurial