From 93fe66fb8ef5c731b46a30a804f74b4bf3b133d7 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Fri, 4 Aug 2023 23:05:22 +0100 Subject: give M extra param for tracking alloc size; macros for allocation --- mem.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'mem.h') diff --git a/mem.h b/mem.h index 8f66fed..0607b14 100644 --- a/mem.h +++ b/mem.h @@ -2,7 +2,18 @@ #define _mem_h #include +#include "val.h" + +void *M(void *p, size_t old, size_t new); + +#define NEW(t) (t*)M(NULL, 0, sizeof(t)) +#define NEW_ARR(t,n) (t*)M(NULL, 0, (n)*sizeof(t)) +#define RENEW_ARR(p,t,old,new) (t*)M((p), (old)*sizeof(t), (new)*sizeof(t)) +#define NEW_OBJ(t, oty) (t*)alloc_obj(sizeof(t), oty) + +#define FREE(p,t) M(p, sizeof(t), 0) + +Obj *alloc_obj(size_t sz, ObjTy oty); -void *M(void *p, size_t sz); #endif -- cgit v1.2.3