Memory Analysis .NET / C#

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Arthur M.

    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
  • Helge Jensen

    #2
    Re: Memory Analysis .NET / C#

    Arthur M. wrote:
    [color=blue]
    > 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).[/color]

    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*measur epoints];
    for ( int i = 0; i < distance*measur epoints; ++i ) {
    foos[i] = new Foo(...);
    if ( i % distance == 0 ) {
    GC.Collect();
    GC.WaitForPendi ngFinalizers();
    mem_spent[i/distance] = GC.GetTotalMemo ry();
    }
    }

    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:helge.je nsen@slog.dk
    sip:helge.jense n@slog.dk
    -=> Sebastian cover-music: http://ungdomshus.nu <=-

    Comment

    • Arthur M.

      #3
      Re: Memory Analysis .NET / C#

      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:
      [color=blue]
      > Arthur M. wrote:
      >[color=green]
      > > 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).[/color]
      >
      > 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*measur epoints];
      > for ( int i = 0; i < distance*measur epoints; ++i ) {
      > foos[i] = new Foo(...);
      > if ( i % distance == 0 ) {
      > GC.Collect();
      > GC.WaitForPendi ngFinalizers();
      > mem_spent[i/distance] = GC.GetTotalMemo ry();
      > }
      > }
      >
      > 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:helge.je nsen@slog.dk
      > sip:helge.jense n@slog.dk
      > -=> Sebastian cover-music: http://ungdomshus.nu <=-
      >[/color]

      Comment

      Working...