Why is a simple "Hello world!"-messagebox eating almost 1.5 MB of my ram? Why not 2.5 kB (the exe size)? :confused:

/Delight
Posted on 2002-06-11 14:10:20 by Delight

Why is a simple "Hello world!"-messagebox eating almost 1.5 MB of my ram? Why not 2.5 kB (the exe size)? :confused:

/Delight



Headline:

and finally after years of mistreatment 'hello world' finally turns bad!!!
:grin: :grin:

kinda hard to answer without some source code, maybe you are allocating mem, or loading a library?
Posted on 2002-06-11 14:14:29 by Terab
and finally after years of mistreatment 'hello world' finally turns bad!!!

hehe...:grin:

nah, it's just a small app thats showing a messagebox and then exits. Nothing more.

edit: I just tried the "minimum" demo that's comes with masm32 and it's almost as bad as my test, 1428 kB!

/Delight
Posted on 2002-06-11 14:19:17 by Delight
what libs and incs are you including? maybe something is loading something else up at runtime.

seems kinda strange
Posted on 2002-06-11 14:24:56 by Terab
I'm using kernel32 and user32 and the only imported APIs (checked after compile) are MessageBox and ExitProcess...

/Delight
Posted on 2002-06-11 14:27:49 by Delight
Memory usage doesn't say much. A lot of stuff goes on internally, libraries are loaded (kernel32/user32 etc), the default heap memory is allocated and much more things windows needs internally.

Thomas
Posted on 2002-06-11 14:27:51 by Thomas
Ok, that explains it, but still - 1428 kB??? That sounds way too much for a 1.5 kB program


/Delight
Posted on 2002-06-11 14:41:04 by Delight
Don't forget a thread uses 1Mb of stack space by default.
Posted on 2002-06-11 14:56:30 by Dr. Manhattan

Don't forget a thread uses 1Mb of stack space by default.


I really didnt know that.

is that for all threads? even ones inside your program?
Posted on 2002-06-11 15:00:28 by Terab
Don't be so alarmed. A *lot* of the memory usage is through shared
DLLs. Also, don't worry about thread stack space, only worry about
*committed* space (usually 4k is committed at a time when accessed,
both for stack and heap, but you can adjust this through linker settings).

So while the memory usage might seem like a lot, it's not too bad.
Ok, reserved (and not committed) memory regions will take a little
space because of page tables - but that's only like 4 bytes per 4k.

So... worry about committed memory... and, in case you have fallen
into the folly of compressing your executables, any large static
buffers.
Posted on 2002-06-11 16:07:15 by f0dder
hmm almost 1.5mb...I have a proggy that has a window, 3 toolbar bitmaps, and another customized open dialog box, Plus it has 10 sub classed edit controls, all just occupies 1.3 - 1.5 MB at most...sometimes it even goes lower than 1mb, sometimes around 800kb, does anybody have any idea, why this is happening? :confused:


I do have witnessed to that 1.5mb MessageBox....
Posted on 2002-06-11 19:49:56 by stryker
Run RadASM 800k,
Load a project 4MB,
Close big app (M$ Word),
Now down to 672k. :)
Posted on 2002-06-11 21:05:19 by bitRAKE
That GetOpenFileName API is a memory hog. That's why I had my own customized open dialog without the extra baggage, GetOpenFileName carries... of course with less functionality. :tongue:
Posted on 2002-06-11 21:16:18 by stryker
I've said it before and I'll say it again - allocated memory is not a
problem, committed memory is. Yes, using DLLs like shell32.dll will
seemingly make your app use a very large extra amount of memory,
but very little of this has physical memory overhead.

Also, I do not recommend using SetProcessWorkingSetSize to trim
your "memory usage", as it might cause your app to have pages
discarded and/or swapped out.
Posted on 2002-06-11 23:44:59 by f0dder
By the way, I've been looking for some time for a utility that displays how much physical memory, and how much on the swap file is allocated for each process.

Does anybody know of such an utility?
Posted on 2002-06-12 03:35:17 by Maverick
invoke SetProcessWorkingSetSize, hProcess, -1, -1


:)



But I think it doesn't work on 9x/ME (don't have API reference here)
Posted on 2002-06-12 03:46:29 by bazik
Also may be used:



call GetCurrentProcess
call EmptyWorkingSet,eax

I am use it for backround program (ex. control FM-radio - 208Kb memory in use).
Posted on 2002-06-12 04:16:08 by Nexo
I only now of FILEMON.EXE, a nice VxD.

I'm not sure if that can help though.

You can get it from:
http://www.sysinternals.com/ntw2k/utilities.shtml
Posted on 2002-06-12 04:28:42 by slop