Continuing the discussion from If we malloc a memory range on glulx, can we dynamically check its extent?:
I understand where this is coming from: if you have a lot of objects of the same size, and can efficiently organize your available memory around these size classes, you need less metadata, less complexity, less computation per (de-)allocation. In contrast, Glulx interpreters have to be reasonably “general purpose”. They can’t even rely on common simplifications made by other general-purpose allocators (e.g., size class rounding or alignment rules) because they have to work with existing heap layouts from saved games created by other interpreters that didn’t necessarily apply the same rules.
However, that doesn’t automatically make it a good idea to layer another allocator on top of it from Glulx code. Besides more complexity and more code that has to be interpreted, there’s a risk of greatly amplifying memory fragmentation. And it’s not a given that this buys you anything. In the world of boring, non-IF software, custom allocators were popular and useful in the dark ages where general-purpose allocators often plainly sucked. However, they stopped making much sense, except possibly for very restricted (de-)allocation patterns, when general-purpose allocators got their act together. This started in the 90s with Doug Lea’s malloc and Wilson et al.'s important “survey and critical review”.
I know that all currently existing Glulx interpreters have very simplistic heap implementations, but some updates will probably be necessary anyway if IE-0008 is ever implemented in some form. I hope that they can become good enough at managing many small heap blocks that layering more allocators over them won’t be worth the trouble. For example, I have a sketch for a design that uses as little as 4 bytes of metadata per allocated block while supporting (de-)allocation in O(log(number of blocks)) time with, hopefully, quite decent constant factors. The only drawback is that the space efficiency hinges on carefully implementing a somewhat fiddly textbook data structure (some sort of B-Tree), so I’ve put off working on that.
It’s a bit of a chicken-and-egg problem: as long as Glulx programs don’t stress malloc/mfree at all, it’s hard to justify putting effort into it, and difficult to get a realistic benchmark for guiding the effort. But as long as malloc/mfree implementations remain as they are, it would be ill-advised to use them heavily. So I look forward to seeing what mad science @Zed will do.