Like Tree2Likes
  • 2 Post By Salem

Memory program size is growing

This is a discussion on Memory program size is growing within the C Programming forums, part of the General Programming Boards category; Hello, I have a program which call only one time malloc at the start of the program. When running, I ...

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    145

    Memory program size is growing

    Hello,

    I have a program which call only one time malloc at the start of the program. When running, I see with 'process-explorer.exe' that memory is growing in little steps. Is this normal? why?

    Thanks in advance
    FS

    P.S.: using Windows 7

  2. #2
    Registered User
    Join Date
    Nov 2012
    Posts
    1,108
    It's hard to tell without seeing the source code. Normally if you have one malloc call then you should also have a corresponding free call. If you are doing it in a loop, then obviously malloc calls will increase the amount of allocated memory over time.

  3. #3
    Registered User
    Join Date
    Feb 2008
    Posts
    145
    Quote Originally Posted by c99tutorial View Post
    It's hard to tell without seeing the source code. Normally if you have one malloc call then you should also have a corresponding free call. If you are doing it in a loop, then obviously malloc calls will increase the amount of allocated memory over time.
    It is called only one time and free at the end of the program. No loop.
    The only datail that maybe is of importance is that I malloc a big chunk of memory (128 MB). I could do it without malloc, inside the code with a big array, but it is a parameter that I let choose to the user, so that is the reason I use malloc.
    This essue is very strange to me.

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,558
    CyberNotes: Windows Memory Usage Explained
    Care to clarify what you mean by "memory increasing"?

    Windows gives you at least half a dozen "memory stats" to ponder over, so you need to get informed as to what they all mean (not to mention the variety of different names for the same thing).

    The VM allocated to the process would have risen at the point of the malloc call, but it would not have immediately been mapped into physical memory.
    This would only happen when your code touched each page in the allocated block. So as you work your way through memory, the working set size might increase (up to some point), when old pages start to get swapped out to the swap file.
    stahta01 and iMalc like this.
    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.

  5. #5
    Registered User
    Join Date
    Nov 2012
    Posts
    1,108
    Without seeing any source code, it's hard to see how a definitive answer can be given. Make a minimal test case that shows this issue, and someone can give a better answer.

  6. #6
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,305
    It depends entirely on what memory stat you are looking at. You should be looking at "Private Bytes".

    If that continually increases then one way or another, your program IS requesting more and more memory. malloc is just one of the many ways your program can acquire more memory / resources. Any API call for which a corresponding release type of method is provided is another.
    E.g. If you call FindFirstFile, then you must call FindClose.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Available memory size
    By Opariti in forum Windows Programming
    Replies: 17
    Last Post: 10-06-2009, 01:06 AM
  2. Growing a Binary Tree
    By hdragon in forum C++ Programming
    Replies: 1
    Last Post: 03-28-2007, 02:41 AM
  3. help with memory size
    By cBegginer in forum C Programming
    Replies: 3
    Last Post: 03-19-2006, 09:28 AM
  4. DCOM Server - Memory keeps growing
    By freestyle in forum Windows Programming
    Replies: 5
    Last Post: 10-25-2002, 11:00 AM

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