[PLUG] Getting the amount of free memory in C
Tyler F. Creelan
creelan at engr.orst.edu
Thu Nov 7 21:10:06 UTC 2002
> > I can't remember how you get the number of bytes of memory
> > available to malloc (in a C program)
IIRC, there's a function to do this in HPUX called "mallinfo", but you
can't call it until you've already written one block of memory. There's
probably something equivalent in Linux.
> Why do you want to do this? Probably best just to ask for the amount
> you want and check the result for error.
I don't think that approach would work in linux-based systems. For
example, see the notes section of the linux malloc manual:
"Linux follows an optimistic memory allocation strategy.
This means that when malloc() returns non-NULL there is no
guarantee that the memory really is available. In case it
turns out that the system is out of memory, one or more
processes will be killed by the infamous OOM killer."
Tyler
On 7 Nov 2002, 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)
>
> Why do you want to do this? Probably best just to ask for the amount
> you want and check the result for error. If you were _able_ to ask how much
> there was accurately, there is no guarantee it would still be there
> when you went to allocate it.
>
>
> --
> 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
>
> _______________________________________________
> PLUG mailing list
> PLUG at lists.pdxlinux.org
> http://lists.pdxlinux.org/mailman/listinfo/plug
>
More information about the PLUG
mailing list