Skip to content

Commit d8abbe3

Browse files
committed
feat: Implement a mark-and-sweep garbage collector for the VM.
1 parent 0d867ad commit d8abbe3

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

src/runtime/gc.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@
1616
// Access the global VM instance
1717
extern VM vm;
1818

19+
void initGC(VM* vm) {
20+
vm->grayCount = 0;
21+
vm->grayCapacity = 0;
22+
vm->grayStack = NULL;
23+
vm->bytesAllocated = 0;
24+
vm->nextGC = 1024 * 1024;
25+
}
26+
1927
void* reallocate(void* pointer, size_t oldSize, size_t newSize) {
2028
vm.bytesAllocated += newSize - oldSize;
2129

0 commit comments

Comments
 (0)