Memory usage From C++ Program

This is a discussion on Memory usage From C++ Program within the C++ Programming forums, part of the General Programming Boards category; Hey everybody, Do any of you know of a way to monitor the memory usage of your C++ program in ...

  1. #1
    Registered User
    Join Date
    Jun 2007
    Posts
    34

    Memory usage From C++ Program

    Hey everybody,

    Do any of you know of a way to monitor the memory usage of your C++ program in Linux from within your program?

    Thank you for your help.

  2. #2
    Registered User
    Join Date
    Nov 2006
    Posts
    519
    you probably have to write your own new/delete operator. That should be easy, because the only thing they have to do es to add/substract sizeof(operand_to_new/delete) to some global value and then execute standard new/delete.

    I never tried this so it could be wrong

  3. #3
    Registered User
    Join Date
    Jun 2007
    Posts
    34
    This will get the usage only for the dynamic memory. However, I want the usage for the whole program. Thanks for trying to help though.

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,494
    Linux maintains a lot of live information in "/var/proc"
    IIRC, each process has it's process ID in there somewhere, and within that may exist the information you're after.
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. memory not released after running program
    By lehe in forum Linux Programming
    Replies: 21
    Last Post: 01-01-2011, 02:32 AM
  2. Client-server system with input from separate program
    By robot-ic in forum Networking/Device Communication
    Replies: 3
    Last Post: 01-16-2009, 02:30 PM
  3. Assignment Operator, Memory and Scope
    By SevenThunders in forum C++ Programming
    Replies: 47
    Last Post: 03-31-2008, 06:22 AM
  4. Program uses a lot of memory and doesnt exit properly
    By TJJ in forum Windows Programming
    Replies: 13
    Last Post: 04-28-2004, 03:13 AM
  5. Is it necessary to write a specific memory manager ?
    By Morglum in forum Game Programming
    Replies: 18
    Last Post: 07-01-2002, 01:41 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21