diff options
author | ubq323 <ubq323@ubq323.website> | 2023-08-04 23:05:22 +0100 |
---|---|---|
committer | ubq323 <ubq323@ubq323.website> | 2023-08-04 23:05:22 +0100 |
commit | 93fe66fb8ef5c731b46a30a804f74b4bf3b133d7 (patch) | |
tree | f3c1121f992ac6d651af22e03ad55a44a8c84e2c /mem.h | |
parent | f67a3fd05c1b2fe8c749fc2f58287b1b14b011d8 (diff) |
give M extra param for tracking alloc size; macros for allocation
Diffstat (limited to 'mem.h')
-rw-r--r-- | mem.h | 13 |
1 files changed, 12 insertions, 1 deletions
@@ -2,7 +2,18 @@ #define _mem_h #include <stddef.h> +#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 |