Re: How to know a class 's size?
- From: "Gabriel Lozano-Morán" <abuse@xxxxxxxxxxxxxxx>
- Date: Wed, 13 Dec 2006 00:18:36 +0100
I assume that you mean an instance of that class (object) and that you want
to know how much memory will be consumed by this object. It depends also on
how the fields are initialized during construction.
So assume that you have an object with a int (4 bytes), string, ushort (2
bytes) properties that are initialized to their default values then your
object would occupy approximately 14 bytes. If you initialize the string
field to "hello world" that would add an additional 40 bytes (not exact
science there) therefore making the size of the object 54 bytes.
Unfortunately it is not that simple. For more information read the following
blog post:
http://blogs.msdn.com/cbrumme/archive/2003/04/15/51326.aspx
And one way to approximately calculate the size of an object (but then again
not accurate):
http://blogs.msdn.com/mab/archive/2006/04/24/582666.aspx
Gabriel Lozano-Morán
The .NET Aficionado
http://www.pointerx.net
"Kevien Lee" <ironpythonster@xxxxxxxxx> wrote in message
news:1165898255.920329.176590@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
If there are some int,string ,ushort filed in a class,How to find out
how it would cost of the memery?
.
- References:
- How to know a class 's size?
- From: Kevien Lee
- How to know a class 's size?
- Prev by Date: Re: # of current physical Threads > 4 000 000 0000
- Next by Date: Re: How to know a class 's size?
- Previous by thread: Re: How to know a class 's size?
- Next by thread: Re: How to know a class 's size?
- Index(es):
Relevant Pages
|