Thread: amount of allocated memory...

  1. #1
    Registered User lobo's Avatar
    Join Date
    Oct 2001

    amount of allocated memory...

    Is there any way (any API support) to find out how much memory has my application allocated in any moment? I have one that uses a lot of malloc()'s and free()'s. I got idea that i could use a global variable to count them all as they are performed, but i'd like to know if there is not better (simplier, possibly more accurate) way to archieve this

  2. #2
    Registered User
    Join Date
    Dec 2001
    Try VirtualQuery

    BTW you can't get the exact size of reserved memory by simply counting all the allocations up, because when the allocation is made, the system often reserves greater space than is requested.

  3. #3
    train spotter
    Join Date
    Aug 2001
    near a computer
    If using the win32 api try looking at its memory functions

    GlobalAlloc() LocalAlloc() GlobalRealloc() GlobalHandle() GlobalLock() ect.

    GlobalSize() will tell you the amount actually allocated. Try keeping count each time you alloc and free adjust the total. Write a function to do it for you (with a static as the total).
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Determing the amount of change(money)
    By Kyeong in forum C Programming
    Replies: 11
    Last Post: 09-30-2008, 04:36 PM
  2. Memory allocated
    By saswatdash83 in forum C Programming
    Replies: 2
    Last Post: 07-15-2008, 02:28 AM
  3. problem with data in allocated memory
    By supi in forum C Programming
    Replies: 3
    Last Post: 06-09-2008, 02:06 AM
  4. Question regarding Memory Leak
    By clegs in forum C++ Programming
    Replies: 29
    Last Post: 12-07-2007, 01:57 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