detecting memory size?

Ketil Malde ketil+haskell at
Thu Jan 29 13:13:28 EST 2004

Glynn Clements <glynn.clements at> writes:

> What do you mean by "memory size"? How much RAM is installed in the
> system? The amount which the process is currently using? The amount
> which the OS might be willing to allocate to your process at any given
> point in time? Something else?

My aplogies for being unclear!  What I really want is the amount of
memory my application can allocate and excercise lively without
causing thrashing.  On my Linux computer, that amounts more or less to
the installed, physical RAM, minus a bit, so I'll settle for that. :-)

(After browsing various information, it seems I'm after the minimum of
physical RAM and getrlimit(RLIMIT_DATA)).

> On Linux, you can read /proc/* (e.g. /proc/meminfo) with readFile,

> getrusage() is relatively portable across Unix variants

Perhaps the best approach would be to use getrusage(), and try to
decrease memory use if/when there is a lot of page faults happening?

BTW, I've started looking into this after a similar problem was
mentioned on the darcs list[0].


If I haven't seen further, it is by standing in the footprints of giants

More information about the Glasgow-haskell-users mailing list