News for hackers. Stuff that matters.
Re:Memory management in C programs by antimagic on Monday March 17, 2014 @07:00AM (#7414302)
I can see where you're going with this, but I think you're being a little glib with the "nearly all the time" bit. There are large chunks of functionality that can't be written that way. The most obvious one is graphical objects, which are typically expensive to render. You can't be destroying / recreating them on the fly, the number of graphical elements in use changes radically over the lifetime of a typical graphical application, and you generally have an event loop, which means the only function that would keep the objects alive is at the top level of the event loop.

I personally tend to look at malloc/free in the same way that I look at if statements. I generally consider code to be cleaner without them, so where possible I will avoid them, but sometimes that's not possible, which is why malloc / free (or if statements) exist.

Re:Memory management in C programs by fdej on Monday March 17, 2014 @08:08AM (#7414552)
Yeah, definitely a little glib. There are certainly prominent exceptions. Still, I think it's a valid general principle. At least, it works well enough for me, and I very rarely have to think consciously about memory management in C. But YMMV, different application domains, and all that.
Re:Memory management in C programs by dllthomas on Monday March 17, 2014 @01:12PM (#7416417)
"The most obvious one is graphical objects, which are typically expensive to render."

For me, in my current project, it's message passing between the low-latency thread and other threads.