Thread: Memory usage From C++ Program

  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 int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    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.

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, 03: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, 03: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