Measuring memory footprint in C/C++ code on FreeBSD

Razmig K strontium90 at gmail.com
Fri Oct 21 10:19:13 UTC 2011


Le 21.10.2011 10:44, Peter Jeremy a écrit :
> On 2011-Oct-20 19:57:31 +0200, Razmig K<strontium90 at gmail.com>  wrote:
> It's not clear whether the program is attempting to determine it's
> own (or a child's) memory footprint, or that of an arbitrary process.
> In the former case, getrusage() is the obvious choice.  This as a
> portable interface.
The program has to determine its own memory footprint. It has no children.

>
> If you want to examine arbitrary processes, the best interface on
> FreeBSD would be kvm_getprocs(3).
>
> BTW, since you mention heap objects, I presume you are aware that
> malloc() uses mmap(), rather than sbrk() to obtain memory.
No I wasn't aware of that.

In few words, the program needs to obtain and report information 
reported by the SIZE column of top, since it is going to be run many 
times, and it is impractical to watch top for this purpose.

Thanks.

~Razmig







More information about the freebsd-hackers mailing list