Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!pasteur!ames!haven!adm!smoke!gwyn From: gwyn@smoke.BRL.MIL (Doug Gwyn ) Newsgroups: comp.lang.c Subject: Re: comp.unix.questions Message-ID: <9942@smoke.BRL.MIL> Date: 29 Mar 89 15:58:16 GMT References: <55125@yale-celray.yale.UUCP> Reply-To: gwyn@brl.arpa (Doug Gwyn (VLD/VMB) ) Followup-To: comp.unix.questions Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 16 In article <55125@yale-celray.yale.UUCP> chen-dahe@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.