best way to discover this process's current memory usage, cross-platform?

MrJean1 MrJean1 at gmail.com
Tue Nov 15 16:16:40 EST 2005


This may work on MacOS X.  An initial, simple test does yield credible
values.

However, I am not a MacOS X expert.  It is unclear which field of the
malloc_statistics_t struct to use and how malloc_zone_statistics with
zone NULL accumulates the stats for all zones.

/Jean Brouwers

#if _MACOSX
#include <malloc/malloc.h>
/* typedef struct malloc_statistics_t {
       unsigned  blocks_in_use;
       size_t    size_in_use;
       size_t    max_size_in_use; -- high water mark of touched memory
       size_t    size_allocated;  -- reserved in memory
   } malloc_statistics_t;
*/
size_t hiwm (
    size_t since)
{
    size_t s;
    malloc_statistics_t t;
    /* get cummulative (?) stats for all zones */
    malloc_zone_statistics(NULL, &t);
    s = t.size_allocated;  /* or t.max_size_in_use? */
    return (s - since);
}
#endif




More information about the Python-list mailing list