memory approximation

D

Douglas

Hi,

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.......

Douglas
 
E

Emmanuel Delahaye

Douglas a couché sur son écran :
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.......

The mapping file generated by your linker can give an idea about the
code size and the static memory. Of course, there is no way to predict
your use of the allocated nor automatic memory.
 
D

Darrell Grainger

Hi,

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.......

There is static and dynamic memory usage. If you have your linker generate
a map file you can know how much static memory will be used. The dynamic
memory usage is a little harder. For that you probably want to ask in a
newsgroup that deals with your compiler and environment. There are often
tools for monitoring stack usage and heap size. Some operating systems
will have performance tools that let you track these issues.

One thing you will need to do is generate worst case scenarios. If the
program has external inputs that affect the running, memory usage will
change with each run. You need to figure out worst case, run it and
monitor the memory usage.

You might also want to ask this question in comp.programming or
comp.software-eng.
 
B

Ben Pfaff

Malcolm said:
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.......
[...]

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".

I've never met a function named coreleft() under Unix, and I
don't think that Win32 provides one either. In fact, as far as I
know only MS-DOS compilers have coreleft(). Because the OP is
talking about swap, he's probably not working under MS-DOS.
 
M

Malcolm

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".
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,145
Messages
2,570,826
Members
47,371
Latest member
Brkaa

Latest Threads

Top