LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Is it possible to know the amount of memory used by a program before running it? (https://www.linuxquestions.org/questions/programming-9/is-it-possible-to-know-the-amount-of-memory-used-by-a-program-before-running-it-708860/)

Gamma_User 03-03-2009 12:59 PM

Is it possible to know the amount of memory used by a program before running it?
 
I would like to know if there is a linux command to verify the amount of memory used by a program. The programs I am using were compiled with gfortran.

sundialsvcs 03-03-2009 09:04 PM

Basically... no.

Although FORTRAN may be somewhat of a simple case because it doesn't really know about "dynamic" memory-allocation, estimates of memory usage "in advance" are both difficult and not particularly useful.

What you can say about FORTRAN is that, once you obtain instrumentation of a particular program-run, "every subsequent run will be pretty-much the same."

telemeister 06-14-2009 08:38 AM

Agree with sundialsvcs that it is fairly difficult to get meaningful numbers..

However, you can get an idea of memory usage in a fortran program by using 'top' with and without the program running. It is a little tricky though.

For example, for top to show the memory being used by an array, you actually have to be using the array while you run top. Hence you have to gludge your code with something to force this to happen while you look at top.

e.g. in this example the while statement will force the array to be used until you bomb out of the program. Top will show you that the program is using about 1000000*4 bytes

program sizer
integer array(1000000)
do while(.true.)
array(1)=1.0
enddo
end

(Obviously, dont do this while others want to use the machine.. it will hog everything!)

Hope this helps

steve


All times are GMT -5. The time now is 08:54 AM.