ucx/allocator.c

changeset 888
af685cc9d623
parent 854
1c8401ece69e
--- a/ucx/allocator.c	Sun Aug 31 14:39:13 2025 +0200
+++ b/ucx/allocator.c	Sat Nov 08 23:06:11 2025 +0100
@@ -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 = &cx_stdlib_allocator;
 
 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