Willy,
Thanks for you reply and all your help. Before I read it I want to
give an update: I've heard that minimizing an app will give a better
idea of the memory usage:
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=301165&SiteID=1
I tried minimizing mine, and its usage went from 27 MB to 2 MB!!
Then I tried to programatically minimize it with WindowState and even
using Win32's ShowWindow(), and neither makes a difference, but if I
do it manually, it works!
I think this is the solution, if I can just get it to work properly.
Quite normal, the GC heap is private and will grow depending your memory
needs, you are converting data read from the file don't you?
Yes, I convert the data read in from the file. Basically just text
data stored in an array of structs internally.
The size of the exe is not relevant here, a 10 lines C# application (4KB
exe) can easily consume 2GB of memory when loaded.
2 GB of memory, but not of code. Can a 1 MB .exe use more than 1 MB
of memory in code, without counting the .NET libraries it uses, and I
assume it shares with all other .NET apps?
Note that the MSIL exe is not shared, nor are the MSIL DLL's. If you wan't
to share the code in memory, you'll have to NGEN your program files
(assemblies).
I don't use any of my own DLLs, only DLLs that some .NET functions
needs that already exist in windows. These DLLs are NOT being
shared??? They can't be loaded for each and every app that references
them? I thought the whole point of DLLs was to avoid this mess. I
was going to make my own DLL so that the code of all the instances
shares the same DLL, but the code size is so small that i dont think
this will help much, since it's not taking up much memory anyway,
unless i'm totally wrong about this.
You should use the performance monitor (perfmon.exe) in order to correctly
measure memory consumption, more you should know exactly what counters to
look at. Important is what memory is shared amongst the processes and what
memory is not shared (Private).
I don't know how to use perfmon.exe, I don't see anywhere that it
allows to view a single process, or maybe you are talking about a
program that doesn't come with windows? I have Process Explorer which
shows me the "Working Set" in private, shareable and shared... is this
the same as what you mean?
What counts here is the Private part, so you should watch the Private
Process counters for your process. The GC heap is part of the private memory
of a process, the amount of memory you consume from the GC heap depends on
your allocation scheme, the more and the larger the objects you create ,the
larger the GC heap grows and consequently the larger your Private bytes.
ok.
The stack space is private too, each managed process runs at least 3
threads, that means 3 * 1MB of private bytes per process (the default stack
being 1MB).
I could probably reduce the stack space by half or more, I bet,
without causing problems, I forgot about that. I'll have to see how I
can change that.
Add to that a minimum 2MB of GC heap space just to get the
application started and 3MB used by the CLR and the other system components
and you have consumed at least of 8MB of private bytes for a do nothing
program.
I've seen a simple do nothing .NET app take 10 MB
So, I would suggest you to start to:
- measure the Virtual bytes consumed by a single instance.
- NGEN the exe and measure again, if the Virtual bytes is considerably lower
keep using the Ngen'd image in your scenario, else forget them.
Is NGEN "Native Image Generator"?
- if the "total virtual bytes" amount doesn't suit your needs, then you'll
have to change your design, I would suggest you to create one single
multi-threaded applications, where each thread takes care of a separate
task, say at most 50 tasks just like you have 50 processes now, much better
is to reduce the number of parallel threads, all depends on your specific
needs.
I think your suggestion is best, but its time consuming and i just
need a quick fix for now. I know everyone hates hearing that, but if
i just reduce the memory by a bit, all will be well. I think if I can
force a minimization of the programs programmatically, then it will
solve my issues.
thanks,
Zytan