Douglas said:
Any suggestions for estimating the amount of memory a program will
use in advance, before it is run. Rules of thumb etc.?
Is it then possible to warn a user that a program is likely to crash
at start up? Swap space issues etc.......
Unless you are coding in a very unusual way, what matters is the calls to
malloc().
Usually you won't know exactly how much memory you need at compile time, but
sometimes you can guess. If you know that most images you work on are
designed for TV, then that will tell you how many pixels are likely to be in
each image, and thus how much memory you need to store them. If you know
that your client has around 200,000 customers, then that will tell you how
much memory you need to hold an account record for each one.
Most programs have a single data structure which accounts for virtually all
the memory used, and you can ignore little bits. Video games are an
exception, when mesh data, images and audio can all gobble large amounts of
memory, so you need to take note of all three.
ANSI C doesn't provide a "coreleft" but it is a common extension. What you
need to do is call this function, and if there isn't enough memory put up a
warning saying "we recommend that at least xx MB be available".