Aug 21

How big can you go?

In case anyone else finds this useful, I wrote a simple C program called maxmalloc which determines both the largest amount of memory a program can allocate in a single request or in a succession of smaller requests. This is minorly interesting in showing the difference in malloc behaviours: on my Linux systems the usable maximum is roughly half a gigabyte smaller than on OS X but Linux can hit that limit using any size block whereas OS X will hit a lower limit if your block size is too small. Mostly, I use it to determine the degree of memory fragmentation caused by libraries (it's trivial to load other libraries in) or to use the -s option so it writes to each allocated block, which is useful for generating VM load or tuning your operating system's overcommit behaviour.

Updated 2009-04-03: Moved the code to Gist for basic version control