[PLUG] Getting the amount of free memory in C
Russell Senior
seniorr at aracnet.com
Thu Nov 7 20:12:25 UTC 2002
>>>>> "Mike" == Mike Witt <mike at computer-arts.net> writes:
Mike> Russell Senior wrote:
>> >>>>> "Mike" == Mike Witt <mike at computer-arts.net> writes:
>>
Mike> I can't remember how you get the number of bytes of memory
Mike> available to malloc (in a C program)
Russell> Why do you want to do this? Probably best just to ask for
Russell> the amount you want and check the result for error. If you
Russell> were _able_ to ask how much there was accurately, there is no
Russell> guarantee it would still be there when you went to allocate
Russell> it.
Mike> Fair enough. I guess I'll have to 'fess up to the real reason.
Mike> I'm trying to find a quick way to find out how much memory a
Mike> fairly complex piece of code (that I inherited) is allocating
Mike> between two operations (approximately) Actually, what I'd like
Mike> is a variable that tells me how much memory my process has
Mike> allocated. I was just going to look at the amount of memory
Mike> "left" because I *thought* there was an easy way to do that. I
Mike> can arrange for the rest of the system to be fairly quiet while
Mike> I run the test.
Given the prevalence of memory allocation/deallocation bugs in C/C++
programs, there are an abundance of memory debugging tools around.
The one I am most familiar with is "electric fence", but I know there
are others. A quick google turned up this:
<http://www.fortran-2000.com/ArnaudRecipes/FreeMemoryDB.html>
Maybe one of them will be appropriate for your problem, or lead to
something that is. These days I write most of my code in Common Lisp
with automatic memory management, so I don't have any fresh experience
chasing these things.
--
Russell Senior ``I've seen every kind of critter God ever made,
seniorr at aracnet.com and I ain't never seen a meaner, lower, more
stinkin' yellow hypocrite than you!''
-- Burl Ives as Rufus Hennessy
More information about the PLUG
mailing list