Thread: how to measure memory

  1. #1
    Registered User
    Join Date
    Jan 2011
    Posts
    222

    how to measure memory

    Hi,

    I was wondering if there exists a function to measure memory on linux OS for a given c++ function. So, what i have is a situation where a person claims that some function he/she wrote needs 20n words of memory to do something. however this function is quite complex and calls some other functions and so on. So i was hoping that there is a way to measure roughly if the memory statement is correct or not.

    So my question is: is something like that possible? Is there a function that i can call to see how much memory was consumed during its execution.

    Example

    Code:
    mem-measure_stat( functio(input) );
    
    cout << mem-measure_stat() << endl;
    where as a result I would get a memory consumption peak for this function

    thnx

    baxy

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Before and after memory state?
    Statistics of Malloc - The GNU C Library

    Hook malloc and free to track usage while the function is being called.
    The GNU C Library
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Measure algorithm speed
    By ingenting in forum C++ Programming
    Replies: 4
    Last Post: 01-22-2010, 01:50 PM
  2. measure run time?
    By Tool in forum C Programming
    Replies: 14
    Last Post: 12-19-2009, 07:56 AM
  3. Measure time
    By anirban in forum C Programming
    Replies: 5
    Last Post: 06-12-2008, 03:53 AM
  4. How to measure memory consumption?
    By nysubmarine in forum C++ Programming
    Replies: 25
    Last Post: 06-27-2006, 03:40 AM
  5. So how does your computer measure up?
    By napkin111 in forum A Brief History of Cprogramming.com
    Replies: 27
    Last Post: 12-30-2002, 12:14 AM