blob: a810bd7e810d76e03ae9eff87a7ea63cf0fcae26 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
#ifndef clox_memory_h
#define clox_memory_h
#include "common.h"
#define ALLOCATE(type, count) \
(type *)reallocate(NULL, 0, sizeof(type) * (count))
#define GROW_CAPACITY(capacity) ((capacity) < 8 ? 8 : (capacity)*2)
#define GROW_ARRAY(type, pointer, oldCount, newCount) \
(type *)reallocate(pointer, sizeof(type) * (oldCount), \
sizeof(type) * (newCount))
#define FREE_ARRAY(type, pointer, oldCount) \
reallocate(pointer, sizeof(type) * (oldCount), 0)
void *reallocate(void *pointer, size_t oldSize, size_t newSize);
#endif
|