Questions about memory usage of programs
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Questions about memory usage of programs

Hybrid View

  1. #1
    Join Date
    Oct 2009
    Posts
    40

    Questions about memory usage of programs

    Let's say the .exe file of a program is 480 kb.When you run the program,does it use about 480kb of memory?
    Functions use memory,variables use memory,objects use memory...

    For example,I wrote two .cpp files,built exe from them.One of the exe files is very short and it is just 5.120byte.The other is longer and 497.644 byte.
    When I run these exe files ,look at task manager's processes section,the shorter exe file seems using 1.044K (is this in KB) and the longer exe seems using 1.056K.Why is the difference between so small?Also why the shorter exe file seems using 1.044 KB? In it's cpp file there is only one function(main) and it has just one variable.The longer exe file has about 6 functions and has more variables including arrays.


    Also do you know a good webpage which describes how applications use memory?
    Last edited by AwArEnEsS; March 12th, 2013 at 08:57 PM.

  2. #2
    Join Date
    Feb 2013
    Location
    United States
    Posts
    56

    Re: Questions about memory usage of programs

    Any program that does anything will use more memory than the size of the executable file. First, that executable file is loaded into memory. Then any DLLs that the process uses are also loaded into that process's memory. Each process has its own copy of the DLLs so that they will not interfere with other processes. Then each process has a stack on which function arguments, return addresses, and local variables are stored. If a process dynamically allocates memory, then even more memory is used. It should also be noted that compilers add a bunch of machine code that your program may or may not use. For example, I have found that C and C++ compilers include code to parse out the command line even if a program does not use the argc or argv parameters.

    Given the enormous amount of memory computers have these days, I would not worry too much about how much memory your application is using, except when it comes to allocating dynamic memory over and over again. I had a case recently where I was allocating arrays that took tens of millions of bytes. The arrays were only used a short time and I freed up their memory when I was done with them. Task manager confirmed that the memory used by my application was bounded. However, it would not be long before I would start getting messages saying that I was running low on virtual memory. Even though the memory used by my application was not growing, Task Manager showed the total memory used by the system kept growing. This memory would not get freed until my application ended. So even though my application was freeing the memory, Windows (XP Professional) was not freeing the memory. I fixed the problem by rewriting part of my program so that instead of freeing up the memory, the memory was reused and thus, no more memory needed to be allocated.
    Last edited by Coder Dave; March 14th, 2013 at 01:07 AM.

  3. #3
    Join Date
    Oct 2009
    Posts
    40

    Re: Questions about memory usage of programs

    Thanks for your answer.

    What does "process" exactly mean?
    When a dll is loaded into memory ,does it's memory usage appear in processes section, inside application's memory usage digits on the task-bar?
    Last edited by AwArEnEsS; March 16th, 2013 at 01:36 PM.

  4. #4
    Join Date
    Feb 2013
    Location
    United States
    Posts
    56

    Re: Questions about memory usage of programs

    A process is an instance of an executable or application. If you have multiple instances of the same executable running at the same time, each instance is its own process. The process includes all of the memory the executable and the loaded DLLs use. Each process has one or more threads of execution.

    When a DLL is loaded by a process, the memory it uses is included with the memory used by the process in the Task Manager.

    DLLs do not appear on the Task Bar. In fact, processes do not really appear on the Task Bar either. If a process has a top level window, that is, one without a parent window, that process's top level window appears on the Task Bar.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center