Here's a good, if dated, introduction to memory usage analysis under
GNU/Linux: http://ktown.kde.org/~seli/memory/analysis.html

exmap
=====

http://www.berthels.co.uk/exmap/

The memory usage can be checked with exmap. This requires compiling a
kernel module::

  aptitude install exmap-source
  m-a a-i exmap
  sudo modprobe exmap

Now:

* run FreeDink and wait until it's loaded,

* run "gexmap" and check Effective Resident, VM and Sole Mapped in
  particular.

Note: exmap hasn't been updated since 2006, so it doesn't compile with
recent kernels, but a minimal patch fixes this for 2.6.26, and I fixed
it for 2.6.32 as well (sadly the bug is archived and I cannot make a
new attachment):
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=495335

There are reports that the userland need to be fixed, but it works
fine for me (besides a couple g++ #include fixes):
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=453852

The latest version of the Debian package can be found at:
http://snapshot.debian.org/package/exmap/0.10-2.1/

I sent the Debian and my patches to the author on 2010-05-20, let's
see if he's alive ;)


memprof
=======

http://www.gnome.org/projects/memprof/

It's a GUI to display a progress bar with how much heap your
application is allocating or freeing. Unlike exmap it's updated in
real time, so you'll immediately notice when your code is eating some
more memory, or when it released it.

It's not packaged in Debian because of a 2002->2006 gap in the
development. But we can easily compile it::

  aptitude install libgtk2.0-dev libgnomeui-dev libglade2-dev libgconf2-dev
  aptitude install binutils-dev # libiberty
  ./configure
  make
  sudo make install

Then you can FreeDink through memprof::

  memprof src/freedink -- --window --game ...

Note that memprof only report the heap size (allocated with malloc),
but there's also the data segment or .bss (Block Started by Symbol,
e.g. static arrays, allocated on program startup).


readelf
=======

It can inspect an executable and in particular display the size of the
data segment::

  readelf -S freedink

For example::

  $ readelf -S freedink | grep .bss
    [24] .bss              NOBITS          0808c0e0 0430c4 71d8e0 00  WA  0   0 32

The third numerical field is the size in hexadecimal, i.e. 7.1MB.
