From 60e752c0c5ae3798105919a43ee194e1e897d429 Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Tue, 7 Sep 2021 22:34:21 -0700 Subject: Chapter 19.3 --- clox/src/memory.h | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'clox/src/memory.h') 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 -- cgit v1.2.3-54-g00ecf