3 ms·
"The GC language is carpet bombing your memory, your performance." Occasionally, the book-keeping to make sure you're able to clean up each allocation individu
by dllthomas 13y ago
"The GC language is carpet bombing your memory, your performance."
Occasionally, the book-keeping to make sure you're able to clean up each allocation individually can be higher than the overhead of garbage collection. Of course, if you're working in C, you can just add garbage collection, either globally (Boehm collector, say, though I don't know how well it actually performs) or only for some particular resources (though then you do need to be sure you are tracking your roots appropriately).
I always find it amusing when I write something that spends a bunch of work making sure everything is freed before it exits. (It's worth doing so valgrind can help you be more confident you're freeing what should be freed as you go along.)
- t1m 13y ago"I always find it amusing when I write something that spends a bunch of work making sure everything is freed before it exits." Yeah, just exit! That's the kind of cool thing about these small, short lived Unix programs like grep and cat - chew memory (stack or heap, up to you!) and bail out - let the OS clean it up. It is essentially the same argument as "prefer large mallocs to small" - the process itself is a 'large malloc'.
- dllthomas 13y agoRight. Like I said, the reason to go to the (programming) effort is that I can make sure it valgrinds clean, which means (if I'm being moderately smart along the way) that I'm not dropping things on the floor that I don't mean to during the program run when I still care about it. Adding a flag for "I don't care about valgrind, go ahead and exit" is then a tiny bit of extra programmer work to save the processor a bit of extra work each run; not sure it's worth it but not sure it's not.
- t1m 13y agoValgrind looks like an amazing tool. I am still a bit giddy to use a C with function prototypes, // style comments and enums, to be honest.
- dllthomas 13y agoValgrind and friends are great. splint has been useful, but needs c99 (and now c11) support. Tangential, but one thing I've recently taken to doing in my C is basically avoiding bare primitive types, preferring to wrap them in a single element struct. This means I can't pass, for instance, price where I mean quantity just because they're "both numbers".