program resource usege

Discussion in 'C Programming' started by Carramba, Jun 28, 2007.

  1. Carramba

    Carramba Guest

    Hello!
    Is there a way in standard C to get information on resource program is
    using? What I would like to know given program A, can A get how much
    memory it have allocated, how much of CPU it using, how many
    instructions have been fetched.
    Or this is strictly platform depended?
    If so what design approach is best to implement multiplatform? working
    through #DEFINE and just insert code depending on platform?

    Thank you in advance!
    Have a nice day :)
    Carramba, Jun 28, 2007
    #1
    1. Advertising

  2. Carramba

    Chris Dollin Guest

    Carramba wrote:

    > Hello!


    Hello!!

    > Is there a way in standard C to get information on resource program is
    > using?


    No.

    > What I would like to know given program A, can A get how much
    > memory it have allocated, how much of CPU it using, how many
    > instructions have been fetched.
    > Or this is strictly platform depended?


    Yes.

    > If so what design approach is best to implement multiplatform? working
    > through #DEFINE and just insert code depending on platform?


    IMAO, no.

    Design the API for how your program wants to fetch the information,
    encode the API as a C header file, and provide a separate implementation
    for each different platform.

    I presume you don't have the choice to not care.

    --
    Chris "what will you do if you do know?" Dollin

    Hewlett-Packard Limited registered no:
    registered office: Cain Road, Bracknell, Berks RG12 1HN 690597 England
    Chris Dollin, Jun 28, 2007
    #2
    1. Advertising

  3. Carramba

    Eric Sosman Guest

    Carramba wrote On 06/28/07 08:34,:
    > Hello!
    > Is there a way in standard C to get information on resource program is
    > using? What I would like to know given program A, can A get how much
    > memory it have allocated, how much of CPU it using, how many
    > instructions have been fetched.
    > Or this is strictly platform depended?
    > If so what design approach is best to implement multiplatform? working
    > through #DEFINE and just insert code depending on platform?


    The only thing C itself provides is the clock()
    function, which you can use to measure the amount of
    CPU time consumed between two calls to clock(). The
    precision of the count varies from system to system
    but is published as the value of CLOCKS_PER_SEC, a
    macro defined in <time.h>. The accuracy of the count
    (not necessarily the same as the precision) also varies,
    and is not available. (For that matter, the definition
    of "CPU time" varies and is also not available ...)

    The other things you mention are strictly platform-
    dependent; not all of them are always available.

    The choice of a design approach depends a good deal
    on what you intend to do with the information (assuming
    you can get it). If you just want to display whatever
    is available, I'd suggest putting everything in one
    self-contained function that you re-implement for each
    platform; your program just calls display_resource_info()
    and that's that. If your program needs to make decisions
    based on these values, things will be harder.

    --
    Eric Sosman, Jun 28, 2007
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dirc Khan-Evans
    Replies:
    1
    Views:
    893
    Karl Seguin
    Oct 17, 2005
  2. avishosh
    Replies:
    2
    Views:
    10,569
    avishosh
    Aug 8, 2004
  3. 466
    Replies:
    6
    Views:
    341
    Mark P
    Nov 4, 2006
  4. smart
    Replies:
    3
    Views:
    287
  5. Heinrich Moser
    Replies:
    1
    Views:
    457
    Heinrich Moser
    Mar 27, 2008
Loading...

Share This Page