2 ms·
> if (previous != NULL) { > previous->next = object; > } else { > vm.objects = object; Ergh. That's much more painful than it needs to be. Maybe try:
by a1369209993 7y ago
> if (previous != NULL) {
> previous->next = object;
> } else {
> vm.objects = object;
Ergh. That's much more painful than it needs to be. Maybe try:
static void sweep() {
Obj** ref = &vm.objects;
while (*ref != NULL) {
if ((*ref)->isMarked) {
(*ref)->isMarked = false;
ref = &(*ref)->next;
} else {
Obj* unreached = *ref;
*ref = unreached->next;
freeObject(unreached);
}
}
}
- 1f60c 7y agoFunny you might say that. Baby’s First Garbage Collector[0] (from the same author) uses this approach. [0]: https://journal.stuffwithstuff.com/2013/12/08/babys-first-garbage-collector/ https://journal.stuffwithstuff.com/2013/12/08/babys-first-ga...