471,336 Members | 877 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,336 software developers and data experts.

Memory Analysis .NET / C#

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
Jul 21 '05 #1
2 2283
Arthur M. wrote:
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[i] = 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:he**********@slog.dk
sip:he**********@slog.dk
-=> Sebastian cover-music: http://ungdomshus.nu <=-
Jul 21 '05 #2
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" wrote:
Arthur M. wrote:
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[i] = 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:he**********@slog.dk
sip:he**********@slog.dk
-=> Sebastian cover-music: http://ungdomshus.nu <=-

Jul 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

18 posts views Thread by jacob navia | last post: by
4 posts views Thread by Hermann Maier | last post: by
1 post views Thread by Charlotte | last post: by
5 posts views Thread by Frank Rizzo | last post: by
10 posts views Thread by deciacco | last post: by
22 posts views Thread by Peter | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.