Minimizing Memory
-
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
-
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
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! -
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!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!
-
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!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
-
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!
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
-
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
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!
-
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!
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