# Sweeping integrated into memory allocation: Why only fixed size objects?

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.

• 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. – Derek Elkins Mar 15 '18 at 6:02