aboutsummaryrefslogtreecommitdiffstats
path: root/clox/src/memory.h
diff options
context:
space:
mode:
authorGravatar Tom Willemse2021-09-07 22:34:21 -0700
committerGravatar Tom Willemse2021-09-07 22:34:32 -0700
commit60e752c0c5ae3798105919a43ee194e1e897d429 (patch)
treee364b168776c5e800e5e17c6812b6217a725c2f8 /clox/src/memory.h
parentc1cbc359e9f1c2451e37d42fc6d2df1aae19f3ec (diff)
downloadcrafting-interpreters-60e752c0c5ae3798105919a43ee194e1e897d429.tar.gz
crafting-interpreters-60e752c0c5ae3798105919a43ee194e1e897d429.zip
Chapter 19.3
Diffstat (limited to 'clox/src/memory.h')
-rw-r--r--clox/src/memory.h16
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