comp.unix.questions

Doug Gwyn gwyn at smoke.BRL.MIL
Thu Mar 30 01:58:16 AEST 1989


In article <55125 at yale-celray.yale.UUCP> chen-dahe at CS.Yale.EDU (Dahe Chen) writes:
>Can anyone tell me a way to find out hwo much memory a C program is
>using at a certain point. I tried with dbx and ps. It seems ps only
>gives the maximum size of memory ever used. Am I right?

This is apparently a UNIX-specific question and really has little to
do with C.  On UNIX, a process typically has a fixed amount of "text"
(instruction) space, a variable (fixed on some architectures) amount
of stack space for activation records, a fixed amount of preinitialized
data space, and a variable amount of "heap" (dynamic) memory space.
The latter is where memory assigned by the C library malloc() routine
comes from.  When a process needs more dynamic memory, it requests that
its heap space be grown by the operating system, via a sbrk() or brk()
system call.  (malloc() does that when necessary.)  There is really no
notion of how much of the current heap space is "used" or "unused"; it
is all available to your process.  That's what is reported by "ps" etc.



More information about the Comp.lang.c mailing list