06-16-2010
61,
12
Join Date: Jun 2010
Last Activity: 26 January 2012, 11:33 PM EST
Location: Portland, OR, USA
Posts: 61
Thanks Given: 1
Thanked 12 Times in 11 Posts
Yes, memusage comes with glibc - or on my OS (CentOS) as part of the glibc-utils package.
As far as best practices go...if you're coding in C, there are a lot of "style" guides available at various sites, but often, it's more the logic of the programming that dictates how it's going to run, performance wise. Good optimizing compilers will do what they do, and more often than not, specific coding styles don't end up producing greatly different binaries. If you want to crank out the most efficient code possible, there are books about that, but it becomes complex, hardware dependent and difficult to manage FAST, along with requiring a lot of esoteric knowledge from the coders.
So, coding guidelines are more for other coders reading the code. Which is definitely worth looking at.
Performance-wise, it's much more about logic, like I said, and ends up being a trade off of a lot of factors - memory, disk I/O, processor time, etc. In some cases, a not terribly elegant loop (which will use a lot of processor) may be better than the alternative that spares the CPU but does a lot of i/o. And so forth.