From 0c647f9f2d0cb20f9ff00efeb5d9fd5c23d4f59b Mon Sep 17 00:00:00 2001 From: cinnaboot Date: Mon, 27 Dec 2021 14:10:23 -0500 Subject: [PATCH] add UTIL_ALLOC macro for calloc --- src/util.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/util.h b/src/util.h index fdc71f2..60087f1 100644 --- a/src/util.h +++ b/src/util.h @@ -41,6 +41,8 @@ char* arenaCopyCStr(memory_arena* arena, const char* input, u32 max_len = MAX_NAME_LENGTH); +#define UTIL_ALLOC(count, type) (type*) utilAllocate(count, sizeof(type)) +void* utilAllocate(u32 count, u32 type_size); char* utilAllocateCStr(const char* str, u32 max_len = 256); void utilSafeFree(void* p); @@ -120,6 +122,14 @@ arenaCopyCStr(memory_arena* arena, const char* input, u32 max_len) return out; } +void* +utilAllocate(u32 count, u32 type_size) +{ + void* out = std::calloc(count, type_size); + assert(out != nullptr); + return out; +} + char* utilAllocateCStr(const char* str, u32 max_len) {