aboutsummaryrefslogtreecommitdiffstats
path: root/clox/src/memory.h
diff options
context:
space:
mode:
authorGravatar Tom Willemse2021-07-08 02:24:24 -0700
committerGravatar Tom Willemse2021-07-08 02:25:13 -0700
commit2c007a8f94d65dc40f638b284db7e374a58b632f (patch)
tree260a1460cdb86c913e785171a85447afc03efddf /clox/src/memory.h
parenta779473cede81f4d3b4eed6f6b4e4184d43ffa87 (diff)
downloadcrafting-interpreters-2c007a8f94d65dc40f638b284db7e374a58b632f.tar.gz
crafting-interpreters-2c007a8f94d65dc40f638b284db7e374a58b632f.zip
Chapter 14.1-6
Diffstat (limited to 'clox/src/memory.h')
-rw-r--r--clox/src/memory.h18
1 files changed, 18 insertions, 0 deletions
diff --git a/clox/src/memory.h b/clox/src/memory.h
new file mode 100644
index 0000000..3c4bdb7
--- /dev/null
+++ b/clox/src/memory.h
@@ -0,0 +1,18 @@
+#ifndef clox_memory_h
+#define clox_memory_h
+
+#include "common.h"
+
+#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