Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Can Copy Collectors outperform malloc/free?

Name: Anonymous 2011-09-16 10:36

So I've heard a couple arguments for this and I'd like to see what you think.

The allocation procedure under copying collectors is most definitely faster than malloc, as malloc has to search through fragments of memory for a sufficiently large block to reserve, whereas allocation under a CC is as simple as incrementing the free heap pointer, much like allocating a stack frame.

When the garbage collector is triggered, it must search through the live set of objects and copy each one over to the new heap. This takes time, but it is limited to the objects in the lives set, so as long as that is reasonably small, this shouldn't take very long. Also, no operation at all is needed on the objects that are no longer referenced. Under malloc and free, free must be called on each and every single one of these objects, the moment they become dead to the program.

I could see garbage collection performing poorly in comparison to malloc and free when the live set of objects is very large and many objects stay live for a very long time. The long living objects would require minimal time for management using malloc and free, whereas the garbage collector may traverse them many times. I suppose this is were using a generational copying collector can come in handy, however. So /prog/, what do think?

Name: Anonymous 2011-09-16 16:44

The thing maybe some of you are overlooking is that many C and C++ programmers who are concerned about memory allocation performance and fragmentation will often use specialized allocators, and malloc to handle the edge-cases.

You can implement arena allocators which just increment a pointer on allocation, and then free everything at once at a predetermined time, like when unloading a module, file or dataset. Way faster than GC and it's not hard to do.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List