From 2c007a8f94d65dc40f638b284db7e374a58b632f Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Thu, 8 Jul 2021 02:24:24 -0700 Subject: Chapter 14.1-6 --- clox/src/memory.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 clox/src/memory.h (limited to 'clox/src/memory.h') 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 -- cgit v1.2.3-54-g00ecf