summaryrefslogtreecommitdiff
path: root/mem.h
blob: 8c528b99a5dce5ae05b84dbe36c020455de23172 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#ifndef _mem_h
#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)
#define FREE_ARR(p,t,old) M(p, (old)*sizeof(t), 0)

Obj *alloc_obj(size_t sz, ObjTy oty);


#endif