aboutsummaryrefslogtreecommitdiffstats
path: root/clox/src/memory.h
diff options
context:
space:
mode:
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