Re: Memory Analysis .NET / C#

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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:helge.jensen@xxxxxxx
> sip:helge.jensen@xxxxxxx
> -=> Sebastian cover-music: http://ungdomshus.nu <=-
>
.



Relevant Pages

  • Re: ADD Vs. INC
    ... But the tokenizer for 'prefix' has work to do. ... Lookup the next 8 input bits in a table, each entry contains the output token and # of bits used, or a pointer to a second-level table. ... (The pointers are actually table offset values, biased by 0x80000000, so any negative table entry means that you need another table lookup. ... This code is otherwise identical to the initial 8-bit lookup, except that since I only need one bit to indicate 1 or 2 used bits, I have room for tokens of up to 30 bits in length. ...
    (comp.lang.asm.x86)
  • Re: debugging memory leaks
    ... most glaring memory leak bug ever? ... That allocates an entire array, but only deletes the first element of it - ... lookup this information, so to prevent the normal delete having to do the ... accidentally calling it on a NULL pointer. ...
    (microsoft.public.vc.language)
  • Re: Small Correction: Convert HEX string to bin
    ... And a table lookup is relatively slow. ... >> justified to have a more complex code but save runtime. ... It would allow the pointer to be ...
    (comp.lang.c)
  • Re: Wireless-testings b43 panics in b43_generate_txhdr on packet transmit
    ... a NULL pointer? ... (or use gdb to lookup the offset). ...
    (Linux-Kernel)
  • Re: Debug my program please.
    ... > 3) Not so much a gotcha as a "what is the benefit?" ... but pointer expressions do occur in practice. ... where lookup() returns a pointer to some type stored in the hashtable. ...
    (comp.lang.fortran)