summaryrefslogtreecommitdiff
path: root/src/alloc.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/alloc.c')
-rw-r--r--src/alloc.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/alloc.c b/src/alloc.c
index 387b196bbee..6a81fed2d69 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -656,7 +656,10 @@ xmalloc (size_t size)
return val;
}
-/* Like the above, but zeroes out the memory just allocated. */
+/* Like the above, but zero out the memory just allocated.
+ Calling this can be faster than allocating and zeroing,
+ as the calloc implementation can avoid the zeroing overhead
+ when obtaining memory directly from the operating system. */
void *
xzalloc (size_t size)
@@ -668,6 +671,21 @@ xzalloc (size_t size)
return val;
}
+/* Like xzalloc, but for an array of N objects each of size S. */
+
+void *
+xcalloc (size_t n, size_t s)
+{
+ void *val = calloc (n, s);
+ if (!val)
+ {
+ size_t size;
+ memory_full (ckd_mul (&size, n, s) ? SIZE_MAX : size);
+ }
+ MALLOC_PROBE (n * s);
+ return val;
+}
+
/* Like realloc but check for no memory and block interrupt input. */
void *