Program Memoryj Usage from 'C'

Bill Poser poser at csli.Stanford.EDU
Thu Dec 14 19:14:17 AEST 1989


The following occurs to me as a way of determining how much
memory has been allocated dynamically, though I am not
clear if the poster really wants to know about heap memory
or stack memory.

First, the sbrk system call, used to extend the processes' data region,
returns the old value of the endpoint. So doing sbrk(0), asking for
an extension of 0 bytes, should give you the current endpoint.

Second, the external variables end, etext, and edata (see section 3 of
the manual) contain the address one beyond the end of the processes
uninitialized data, program text, and initialized data. So the
amount of memory allocated on the  should be:

	sbrk(0) - end + 1



More information about the Comp.unix.wizards mailing list