Re:Introduction to Functional Programming in OCaml
by wtetzner on Monday September 05, 2016 @11:35AM
(#12430817)
> Hardcoding the optimal resource reclamation strategy into your program will always be more efficient at runtime than not doing so.
That depends on what you mean by efficient. Since this thread is about real-time stuff, you may be right (though I wouldn't be on it). However, often a GC will give better throughput.
It depends on the style of memory management on both sides, of course. But for example, in a situation where you call `free` (or, `delete`, etc.) to free each allocation, you might end up doing more work than a copying GC, where you only have to track live references.
Re:Introduction to Functional Programming in OCaml
by catnaroek on Monday September 05, 2016 @12:27PM
(#12431078)
Of course, “the optimal resource reclamation strategy” depends on what you want to optimize in the first place. I didn't intend to suggest it's always “free every resource as soon as you don't need it anymore”.
Hardcoding the optimal resource reclamation strategy into your program will always be more efficient at runtime than not doing so. What “real-time” garbage collection gives you is only freedom from arbitrarily long pauses, not closeness to the optimal strategy. Furthermore, it doesn't come for free: it imposes some memory usage overhead. Finally, garbage collection simply can't handle resources that need to be reclaimed in a deterministic fashion, like file handles, GUI objects and network connections.