Memory Analysis .NET / C#

G

Guest

Does anyone know of a way to pin point true memory utilization on a per
object / allocation basis in dot net.

The problem that i'm having is projecting the amount of memory that will be
required by an application.

Obviously there is a component size (i.e. a class that is using 2 32bit
integers will use 8byte) but then there is a question of overhead for .NET
management (i.e. vtables, lookup tables, garbage collector pointer on a per
instance basis etc etc etc... ) Is there a way to determine how much memory
is actually being used by an object (mathematical formula is fine as well).

Going to the same point - how much memory does a delegate take up? In C it
used to be size of an integer....

In the end of the day my problem is this:

If i have 10 million objects loaded in ram, each is at about 40 bytes of
internal value types with 10 delegates within with one function per delegate
(or multicast delegate should I say) how much memory is going to be used when
I fire it up :)

My estimates ranged anywhere from 3 Gb to 9 Gb:) depending on crude methods
I used to evaluate per instance memory utilization
 
H

Helge Jensen

Arthur said:
Obviously there is a component size (i.e. a class that is using 2 32bit
integers will use 8byte) but then there is a question of overhead for .NET
management (i.e. vtables, lookup tables, garbage collector pointer on a per
instance basis etc etc etc... ) Is there a way to determine how much memory
is actually being used by an object (mathematical formula is fine as well).

how about just doing a test: (warning: untested code)

int measurepoints = X;
int distance = Y;
long mem_spent = new long[measurepoints];
Foo[] foos = new Foo[distance*measurepoints];
for ( int i = 0; i < distance*measurepoints; ++i ) {
foos = new Foo(...);
if ( i % distance == 0 ) {
GC.Collect();
GC.WaitForPendingFinalizers();
mem_spent[i/distance] = GC.GetTotalMemory();
}
}

it will show you how memory-usage relates to the number of objects.

You can even try and run it on your actual code and get a very accurate
estimate that way.
 
G

Guest

Thanks for the suggestion; that is exactly what i ended up doing... in truth
though I'm looking for a well defined formula that says that a 'pointer' to
an object takes up (guessing) 16 bytes 4 for real pointer 4 for garbage
collection 4 for a lookup table and 4 for something else; that way I would
not need to do a guess work ...

Helge Jensen said:
Arthur said:
Obviously there is a component size (i.e. a class that is using 2 32bit
integers will use 8byte) but then there is a question of overhead for .NET
management (i.e. vtables, lookup tables, garbage collector pointer on a per
instance basis etc etc etc... ) Is there a way to determine how much memory
is actually being used by an object (mathematical formula is fine as well).

how about just doing a test: (warning: untested code)

int measurepoints = X;
int distance = Y;
long mem_spent = new long[measurepoints];
Foo[] foos = new Foo[distance*measurepoints];
for ( int i = 0; i < distance*measurepoints; ++i ) {
foos = new Foo(...);
if ( i % distance == 0 ) {
GC.Collect();
GC.WaitForPendingFinalizers();
mem_spent[i/distance] = GC.GetTotalMemory();
}
}

it will show you how memory-usage relates to the number of objects.

You can even try and run it on your actual code and get a very accurate
estimate that way.

--
Helge Jensen
mailto:[email protected]
sip:[email protected]
-=> Sebastian cover-music: http://ungdomshus.nu <=-
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top