In our language design book, it is mentioned that GC sweep can be integrated into allocation, such that when you call malloc for example, you sweep until you find a fitting object, which you then return (i.e. sweeping is not a different procedure).

It, however, also mentions that this is only viable when the objects all have the same size. Why is that? It seems to me that it should be possible, since the sizes of the objects are known from the metadata etc.

  • $\begingroup$ I suspect the issue is that if you're not compacting, then you need to walk over the beginning of the heap over and over again (or at least starting from the first free block). If the blocks are the same size, then you only need to walk from the last allocated block. $\endgroup$ Mar 15 '18 at 6:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy