// // Created by 李晓明 on 2023/8/16. // #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) // oldSize newSize Operation // 0 Non‑zero Allocate new block. // Non‑zero 0 Free allocation. // Non‑zero Smaller than oldSize Shrink existing allocation. // Non‑zero Larger than oldSize Grow existing allocation. void *reallocate(void *pointer, size_t oldSize, size_t newSize); #endif//CLOX_MEMORY_H