what tha f**k. what's wrong with the task manager or my program is it?

when i run my program which is barely 5KB, windows task manager shows that my proggie is using approx. 2.0 MB of memory. if i minimize and/or restore it, it drops down to around 400 KB. what tha hell is goin on with this. my prog is just 5KB. why does it need to use SOOOOOO MUUUCCCHHH memory. shit.
Posted on 2003-12-17 20:20:59 by evil__donkey
Task Manager reports the working set size, it does have some connection with the amount of memory your program is using but not much. Try this, it will trim the process working set:

invoke GetCurrentProcess
invoke SetProcessWorkingSetSize, eax, -1, -1
Posted on 2003-12-17 20:34:51 by donkey
where do i put that? at the start before calling winmain? i put it there but not much difference was noted. the starting mem usage decreased to 1.5 MB. what does this do?
Posted on 2003-12-17 20:56:43 by evil__donkey
For the biggest difference you put it in WM_CREATE, all it does is trim off some of the fat that Windows attaches to an executable by swapping it out of RAM and back, no harm at all. It is a temporary change though, when you create an new window it will probably jump right back up. You will have trouble getting under 500K for a visible window and 100K for a hidden window. Remember that you have to load part of alot of modules to make a Windows program run and the process has to be allocated a certain amount of memory to allow it to execute.
Posted on 2003-12-17 21:03:00 by donkey
Other software on your PC might also have DLLs that are loaded into all process address spaces whether you want them or not. For example, I see that the software for my mouse is loaded into all apps so my custom mouse buttons work in them. These extra DLLs will cause the reported memory usage to be larger than it normally should be.

You can see all DLLs loaded into your exe by using the very helpful (and free) Process Explorer:

Posted on 2003-12-17 21:50:42 by Mecurius
wow that does work. may be i'll fiddle with this a bit more. any place where i can dig up info on this.
Posted on 2003-12-17 22:02:16 by evil__donkey
If you're looking for info on working sets there is a bit (not much) at MSDN .
Posted on 2003-12-17 22:09:54 by donkey
Besides DLL's
The page tables for each application require approx 4M :grin:
So this is what windows is :tongue:
Posted on 2003-12-21 21:32:44 by BogdanOntanu
I have an approach to the memory usage reported by task manager, write the problem on an absorbant piece of paper, hang it on a nail in the loo and make good use of it next time you go.

There are ways to test stressed memory usage on a system yet you will find that many small apps will run within the remaining memory available.

Use whichever version of "GlobalMemoryStatus" works on your box and get a far better idea of what uses what.

Posted on 2003-12-22 03:12:06 by hutch--
write the problem on an absorbant piece of paper, hang it on a nail in the loo and make good use of it next time you go

you do that hutch--?.....hehe.

hangin in the loo.......hehehe
Posted on 2003-12-22 03:54:29 by evil__donkey

The page tables for each application require approx 4M :D

Hrm, verify this? I thought 9x uses a PTE-patching method, and NT (while having a separate CR3 per process) re-uses PTEs?

EvilDonkey, don't worry too much about the task manager figures, unless you understand them :) As already mentioned, the number showed by default includes shared memory like DLLs - thus it's not the amount of physical memory allocated to your app. On NT (at least 2k+) you also have perfmon.msc which can give better counters. Also, you can add more information columns on the NT task manager - add 'Handles' and 'GDI Objects', and the taskmgr can serve as a quick overview telling whether your app leaks like crazy =)

The SetProcessWorkingSetSize trick is best done once, right after all your init code - or perhaps after calling not-often-used library routines that involve a lot of code being executed. And it really is mostly a trick, to make the magical figures in the task manager go lower and amaze your friends ;)
Posted on 2003-12-22 07:29:40 by f0dder
Someone write me some debugging code which queries the performance mon please :) I'll add it to my handy dandy debug module to be used to identify leaks and bottlenecks in my code :D
(Yes, I'm serious :tongue: )
Posted on 2003-12-22 07:33:10 by Homer