Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. ATL / WTL / STL
  4. Minimizing Memory

Minimizing Memory

Scheduled Pinned Locked Moved ATL / WTL / STL
questionc++delphicomperformance
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Matt Gerrans
    wrote on last edited by
    #1

    I've got a little app that I want to use a minimal amount of memory. I have one function that creates COM object (CComPtr), uses it, then returns, the memory used by the program (in Task Manager) jumps up about 1.5 MB, but never drops back down. It's not simply a leak, because calling the function many times doesn't cause the memory usage to grow. Another question along these lines: I've seen some programs (like smss, lsass, cmd and EmEditor when minimized) that are able to use a relatively small amount of memory, but when I create a simple "hello world" program (without MFC or any other framework slop) with MSVC or Borland's compiler, it uses at least 2 MB. Anyone know what trick is being used in these? Matt Gerrans

    M 1 Reply Last reply
    0
    • M Matt Gerrans

      I've got a little app that I want to use a minimal amount of memory. I have one function that creates COM object (CComPtr), uses it, then returns, the memory used by the program (in Task Manager) jumps up about 1.5 MB, but never drops back down. It's not simply a leak, because calling the function many times doesn't cause the memory usage to grow. Another question along these lines: I've seen some programs (like smss, lsass, cmd and EmEditor when minimized) that are able to use a relatively small amount of memory, but when I create a simple "hello world" program (without MFC or any other framework slop) with MSVC or Borland's compiler, it uses at least 2 MB. Anyone know what trick is being used in these? Matt Gerrans

      M Offline
      M Offline
      Michael Dunn
      wrote on last edited by
      #2

      When you free memory or release COM objects, the memory manager doesn't immediately remove that used memory from your working set. It assumes that you will probably request memory again pretty soon, which is true for most apps. To trim unused memory from your working set, call SetProcessWorkingSetSize(GetCurrentProcess(), -1.-1) or use the /WS linker switch. --Mike-- Personal stuff:: Ericahist | Homepage Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ ---- Laugh it up, fuzzball. You cannot stop me with paramecium alone!

      J M 2 Replies Last reply
      0
      • M Michael Dunn

        When you free memory or release COM objects, the memory manager doesn't immediately remove that used memory from your working set. It assumes that you will probably request memory again pretty soon, which is true for most apps. To trim unused memory from your working set, call SetProcessWorkingSetSize(GetCurrentProcess(), -1.-1) or use the /WS linker switch. --Mike-- Personal stuff:: Ericahist | Homepage Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ ---- Laugh it up, fuzzball. You cannot stop me with paramecium alone!

        J Offline
        J Offline
        Jorgen Sigvardsson
        wrote on last edited by
        #3

        Arigato Gozaimashita Michael-san. That's a little gem my colleague will appreciate. :) Do you know why a process drops a lot of memory when its windows are minimized by the way? Open task manager, and look at let's say devenv.exe. Minimize it and you'll see a huge drop in memory consumption. Do you have any idea what that's all about? I suppose it's just a "trick" as the VM size doesn't change a bit. -- Arigato gozaimashita!

        M 1 Reply Last reply
        0
        • M Michael Dunn

          When you free memory or release COM objects, the memory manager doesn't immediately remove that used memory from your working set. It assumes that you will probably request memory again pretty soon, which is true for most apps. To trim unused memory from your working set, call SetProcessWorkingSetSize(GetCurrentProcess(), -1.-1) or use the /WS linker switch. --Mike-- Personal stuff:: Ericahist | Homepage Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ ---- Laugh it up, fuzzball. You cannot stop me with paramecium alone!

          M Offline
          M Offline
          Matt Gerrans
          wrote on last edited by
          #4

          Excellent! I wanted my little process to return from the ~4MB it jumped to after using the COM objects, to the ~2MB it started from -- this call popped it all the way down to ~500KB. Thanks a million! ...or should I say thanks 3.5 million? :) Matt Gerrans

          1 Reply Last reply
          0
          • J Jorgen Sigvardsson

            Arigato Gozaimashita Michael-san. That's a little gem my colleague will appreciate. :) Do you know why a process drops a lot of memory when its windows are minimized by the way? Open task manager, and look at let's say devenv.exe. Minimize it and you'll see a huge drop in memory consumption. Do you have any idea what that's all about? I suppose it's just a "trick" as the VM size doesn't change a bit. -- Arigato gozaimashita!

            M Offline
            M Offline
            Michael Dunn
            wrote on last edited by
            #5

            Iie, dou itashimashite! :) I remember seeing on RaymondC's blog that when you minimize a window, its memory is immeidately marked for swapping, so it will be one of the first bits of memory swapped to disk if some other app needs more physical RAM. OT: I think you asked a while ago about the spalling of "gozaimashita". There is a pronunciation rule that [i] and [u] become voiceless between voiceless sounds. So in "shita", [i] is between [sh] and [t] (both voiceless) so the [i] becomes voiceless as well, and the sound blends into the [sh] part. (Sorry if this is too technical, I don't really know how to explain it without using linguistic terms.) When you write "gozaimashita" it is 6 characters (go-za-i-ma-shi-ta) and the romanization reflects that. --Mike-- Personal stuff:: Ericahist | Homepage Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ ---- "Linux is good. It can do no wrong. It is open source so must be right. It has penguins. I want to eat your brain."   -- Paul Watson, Linux Zombie

            J 1 Reply Last reply
            0
            • M Michael Dunn

              Iie, dou itashimashite! :) I remember seeing on RaymondC's blog that when you minimize a window, its memory is immeidately marked for swapping, so it will be one of the first bits of memory swapped to disk if some other app needs more physical RAM. OT: I think you asked a while ago about the spalling of "gozaimashita". There is a pronunciation rule that [i] and [u] become voiceless between voiceless sounds. So in "shita", [i] is between [sh] and [t] (both voiceless) so the [i] becomes voiceless as well, and the sound blends into the [sh] part. (Sorry if this is too technical, I don't really know how to explain it without using linguistic terms.) When you write "gozaimashita" it is 6 characters (go-za-i-ma-shi-ta) and the romanization reflects that. --Mike-- Personal stuff:: Ericahist | Homepage Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ ---- "Linux is good. It can do no wrong. It is open source so must be right. It has penguins. I want to eat your brain."   -- Paul Watson, Linux Zombie

              J Offline
              J Offline
              Jorgen Sigvardsson
              wrote on last edited by
              #6

              Michael Dunn wrote: When you write "gozaimashita" it is 6 characters (go-za-i-ma-shi-ta) and the romanization reflects that. Ah, so basically, "shi" is a hiragana(?) character, and "shi" is its name? I guess the same applies to our alphabet. H's name is "age", but it's not pronounced that way when used as part of a word. Michael Dunn wrote: There is a pronunciation rule that [i] and [u] become voiceless between voiceless sounds. Do you know the official explanation of why [u] isn't pronounced in words such as desu? I read on a webpage that only speakers of old dialects pronounce [u], and that it has apparently been optimized away with time. The web page I read it on didn't seem all that serious (rude japanese expressions was a large part of the repertoire). -- Arigato gozaimashita!

              M 1 Reply Last reply
              0
              • J Jorgen Sigvardsson

                Michael Dunn wrote: When you write "gozaimashita" it is 6 characters (go-za-i-ma-shi-ta) and the romanization reflects that. Ah, so basically, "shi" is a hiragana(?) character, and "shi" is its name? I guess the same applies to our alphabet. H's name is "age", but it's not pronounced that way when used as part of a word. Michael Dunn wrote: There is a pronunciation rule that [i] and [u] become voiceless between voiceless sounds. Do you know the official explanation of why [u] isn't pronounced in words such as desu? I read on a webpage that only speakers of old dialects pronounce [u], and that it has apparently been optimized away with time. The web page I read it on didn't seem all that serious (rude japanese expressions was a large part of the repertoire). -- Arigato gozaimashita!

                M Offline
                M Offline
                Michael Dunn
                wrote on last edited by
                #7

                Jörgen Sigvardsson wrote: Do you know the official explanation of why [u] isn't pronounced in words such as desu? Ah, actually I left out something in my earlier post. [i] and [u] also become voiceless after a voiceless sound when they are at the end of a word, such as in "desu" or the verb ending "masu". This is a common phenomenon in languages, unstressed vowels can be "reduced" since they aren't the focal point of the word. For example in English, "several" is usually said as two syllables "sev-ral" with the middle "e" being dropped entirely. A similar thing happens with consonants in many languages, eg German and Russian. In German "tag", the [g] becomes devoiced to [k]. --Mike-- Personal stuff:: Ericahist | Homepage Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups