Measuring memory ? 
Author Message
 Measuring memory ?

Hi,

Is there any way to measure how much memory a specific function (or
program) is using ?

Any help ?

Thanks



Mon, 09 Aug 2004 07:55:35 GMT  
 Measuring memory ?

Quote:

> Is there any way to measure how much memory a specific function (or
> program) is using ?

Code or data?
--
"Your correction is 100% correct and 0% helpful. Well done!"
--Richard Heathfield


Mon, 09 Aug 2004 08:00:00 GMT  
 Measuring memory ?

Quote:

> > Is there any way to measure how much memory a specific function (or
> > program) is using ?

> Code or data?

Automatic data or from the free-store?  Actual memory pages or virtual
memory pages?  If the code segments are memory mapped, do we count the
loaded pages or all the pages?  Is it a peak or average figure that is
wanted?

An evil and cheesy hack to find an approximation of the current size of
automatic memory (highly inaccurate, of course...):
/*
** If questioned, Dann Corbit will deny any knowledge of
** this program's existence.
*/
#include <stdio.h>

char           *g_end_I_am_a_cheesy_hack;
char           *g_beg_I_am_a_cheesy_hack;
double          g_distance;

void            stack_eater(int d)
{

    long            consume[2000];

    g_end_I_am_a_cheesy_hack = (char *) consume;
    g_end_I_am_a_cheesy_hack += sizeof consume;

    /* May need to reverse this if stack grows other way: */
    g_distance = g_beg_I_am_a_cheesy_hack - g_end_I_am_a_cheesy_hack;
    printf("%.0f bytes of stack gobbled, roughly.\n", g_distance);
    if (d < 100)
        stack_eater(++d);

Quote:
}

int             main(void)
{
    char            I_am_the_first_thing_on_the_pile;   /* This can't move
*/
    g_beg_I_am_a_cheesy_hack = &I_am_the_first_thing_on_the_pile;
    stack_eater(0);
    return 0;
Quote:
}

--
C-FAQ: http://www.eskimo.com/~scs/C-faq/top.html
 "The C-FAQ Book" ISBN 0-201-84519-9
C.A.P. FAQ: ftp://cap.connx.com/pub/Chess%20Analysis%20Project%20FAQ.htm


Mon, 09 Aug 2004 09:23:29 GMT  
 Measuring memory ?
On 20 Feb, in article


Quote:
>Hi,

>Is there any way to measure how much memory a specific function (or
>program) is using ?

There is no portable way of doing this in C. Your OS may be able to provide
information about a program/process and may have other facilities such as
debuffers that can provide a finer breakdown. Try asking in a newsgroup
relating to your particular compiler or OS.

--
-----------------------------------------


-----------------------------------------



Mon, 09 Aug 2004 18:15:17 GMT  
 Measuring memory ?

Quote:
> > > Is there any way to measure how much memory a specific function (or
> > > program) is using ?

> > Code or data?

> Automatic data or from the free-store?  Actual memory pages or virtual
> memory pages?  If the code segments are memory mapped, do we count the
> loaded pages or all the pages?  Is it a peak or average figure that is
> wanted?

Thanks for your reply!
Actually I do not know what type of memory. The idea is that I have a
working function that I want to hand out to someone without giving out
the code. And I would like to have some kind of specs about my
function like how fast my algorithm works and how much memory it
requires. I have a way to measure speed, now I need some kind of
memory estimate. I do not know anything about different types of
memory ... any body can enligth me on that mattter ?

Thanks



Tue, 10 Aug 2004 04:47:02 GMT  
 Measuring memory ?

Quote:
>> > > Is there any way to measure how much memory a specific function (or
>> > > program) is using ?

>> > Code or data?

>> Automatic data or from the free-store?  Actual memory pages or virtual
>> memory pages?  If the code segments are memory mapped, do we count the
>> loaded pages or all the pages?  Is it a peak or average figure that is
>> wanted?

>Thanks for your reply!

One of the other answers was better really.

Quote:
>Actually I do not know what type of memory. The idea is that I have a
>working function that I want to hand out to someone without giving out
>the code. And I would like to have some kind of specs about my
>function like how fast my algorithm works and how much memory it
>requires. I have a way to measure speed, now I need some kind of
>memory estimate. I do not know anything about different types of
>memory ... any body can enligth me on that mattter ?

This is entirely OS specific. Your OS probably has fns to do this, but
you'd hvae to ask in an OS-specific group. This isn't it.
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>


Tue, 10 Aug 2004 05:08:52 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. tool to measure memory usage

2. Q: Measuring per-module memory usage?

3. Pixels, Points and measuring strings

4. time measure of procedures

5. measuring (run) time

6. How to measure code size?

7. Measure time of operation

8. Halstead Complexity Measures

9. Measuring network traffic

10. Program to do simple performance measures?

11. measure time

12. Question: How to measure the excution time

 

 
Powered by phpBB® Forum Software