Re: How much memory do managed code objects take, really?

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

From: Marcos Stefanakopolus (taruntius_at_hotmail.com)
Date: 01/07/05


Date: Fri, 7 Jan 2005 15:50:10 -0800


>> The method I usually use is to create a test program which creates an
>> empty array of hundreds of thousands of references, finds out the
>> amount of memory used, fills in the array with hundreds of thousands of
>> objects, finds out the amount of memory *then* used, and then looks at
>> the difference between the two.

And how do you do the "finds out the amount of memory used" part? Do you
have some code you could share? Somehow I doubt that what Task Manager will
tell me is either precise or accurate enough.

>> > In C++, if I build 1 WorldTriangle, I've used 12 bytes for pointers to
>> > the
>> > vertices, and 36 bytes for the vertex objects themselves. In C#, How
>> > much
>> > memory have I really used?
>>
>> Each object has an overhead of 8 bytes. Each float takes 4 bytes. Each
>> reference takes 4 bytes.

So you're saying that all reference types have an 8-byte overhead, while
value types have a 0 byte overhead? If true, that's probably sufficient for
my purposes.

> Sorry, I meant to mention - there are also potential gaps due to
> padding between elements.

Yes, I'm aware of that potential issue. Fortunately, there's
[StructLayoutAttribute(LayoutKind.Explicit)] to help with that.



Relevant Pages

  • Re: clearing a global array
    ... new empty Array to the variable globalArray: ... If there's only a single reference, ... 'arr = ', too. ...
    (comp.lang.javascript)
  • Re: test value
    ... Shane wrote: ... held in a scalar, but there is 'no' value held in there ... $val contains a reference to an empty array, ...
    (comp.lang.perl.misc)
  • Re: test value
    ... John Bokma wrote: ... held in a scalar, but there is 'no' value held in there ... $val contains a reference to an empty array, ...
    (comp.lang.perl.misc)
  • Re: test value
    ... Josef Moellers wrote: ... held in a scalar, but there is 'no' value held in there ... $val contains a reference to an empty array, ...
    (comp.lang.perl.misc)
  • Re: java object member layout question
    ... > Also for an array the overhead is 16 bites. ... > I am also looking for reference of the answers to my question. ... as to how much memory overhead is involved in a single object. ... "Java" incurs 8 bytes per object of overhead. ...
    (comp.lang.java.programmer)