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

MrJean1 MrJean1 at gmail.com
Tue Nov 15 01:45:26 EST 2005


My suggestion would also be to use sbrk() as it provides a high-water
mark for the memory usage of the process.

Below is the function hiwm() I used on Linux (RedHat).  MacOS X and
Unix versions are straigthforward.  Not sure about Windows.

/Jean Brouwers

#if _LINUX
#include <malloc.h>

size_t hiwm (void) {
    /*  info.arena - number of bytes allocated
     *  info.hblkhd - size of the mmap'ed space
     *  info.uordblks - number of bytes used (?)
     */
    struct mallinfo info = mallinfo();
    size_t s = (size_t) info.arena + (size_t) info.hblkhd;
    return (s);
}

#elif _MAXOSX || _UNIX
#include <unistd.h>

size_t hiwm (void) {
    size_t s = (size_t) sbrk(0);
    return (s);
}

#elif _WINDOWS
size_t hiwm (void) {
    size_t s = (size_t) 0; /* ??? */
    return (s);
}

#endif




More information about the Python-list mailing list