Browse Source

add UTIL_ALLOC macro for calloc

main
cinnaboot 5 years ago
parent
commit
0c647f9f2d
  1. 10
      src/util.h

10
src/util.h

@ -41,6 +41,8 @@ char* arenaCopyCStr(memory_arena* arena,
const char* input, const char* input,
u32 max_len = MAX_NAME_LENGTH); 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); char* utilAllocateCStr(const char* str, u32 max_len = 256);
void utilSafeFree(void* p); void utilSafeFree(void* p);
@ -120,6 +122,14 @@ arenaCopyCStr(memory_arena* arena, const char* input, u32 max_len)
return out; return out;
} }
void*
utilAllocate(u32 count, u32 type_size)
{
void* out = std::calloc(count, type_size);
assert(out != nullptr);
return out;
}
char* char*
utilAllocateCStr(const char* str, u32 max_len) utilAllocateCStr(const char* str, u32 max_len)
{ {

Loading…
Cancel
Save