diff options
Diffstat (limited to 'clox/src/memory.h')
-rw-r--r-- | clox/src/memory.h | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/clox/src/memory.h b/clox/src/memory.h index 3c4bdb7..a810bd7 100644 --- a/clox/src/memory.h +++ b/clox/src/memory.h @@ -3,16 +3,18 @@ #include "common.h" -#define GROW_CAPACITY(capacity) \ - ((capacity) < 8 ? 8 : (capacity) * 2) +#define ALLOCATE(type, count) \ + (type *)reallocate(NULL, 0, sizeof(type) * (count)) -#define GROW_ARRAY(type, pointer, oldCount, newCount) \ - (type*)reallocate(pointer, sizeof(type) * (oldCount), \ - sizeof(type) * (newCount)) +#define GROW_CAPACITY(capacity) ((capacity) < 8 ? 8 : (capacity)*2) -#define FREE_ARRAY(type, pointer, oldCount) \ +#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); +void *reallocate(void *pointer, size_t oldSize, size_t newSize); #endif |