Re: How to know a class 's size?



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?



.



Relevant Pages

  • Re: Record type flushing
    ... If you try to assign a new value to a string field in that ... reference, so the compiler's code tries to release that reference before ... The Initialize procedure can be used to solve that problem. ... If you're using the shell's memory manager, ...
    (alt.comp.lang.borland-delphi)
  • Re: Lets make it backwards compatible :D
    ... > Incorrect use of Initialize. ... it is a string. ... The pointer storage would point to the null terminator. ... Storage now holds a string reference. ...
    (alt.comp.lang.borland-delphi)
  • Re: Is there a difference between passing "" and passing Nothing to a Windows API ?
    ... string to string variables" lazy because it prevents the developer from ... It's to always initialize it to something when I declare it. ... Anyhow, please describe "potential problems?" ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Access types as parameters
    ... Initialize is doing is to set up some fields in Button: ... Most GTK subprograms do need access values; the same is true of any ... package Window is ... function Name_Dispatch return String; ...
    (comp.lang.ada)
  • Re: Array reinitialize
    ... |> | by a character string literal, ... |> | initialize the elements of the array." ... | is really 21 characters long. ... an array via an aggregate initialiser, ...
    (alt.comp.lang.learn.c-cpp)