467,081 Members | 1,228 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,081 developers. It's quick & easy.

Size of a class

Anybody know how to determine the "sizeof" a class?

TYIA

Jack

ja**********@netscape.NOSPAM.net
Nov 15 '05 #1
  • viewed: 3746
Share:
2 Replies
sizeof( type )?

"Jack" <ja**********@netscape.net> wrote in message
news:#q**************@TK2MSFTNGP11.phx.gbl...
Anybody know how to determine the "sizeof" a class?

TYIA

Jack

ja**********@netscape.NOSPAM.net

Nov 15 '05 #2
Depending on what you want, specifically, there are a few answers.
For managed classes, there is no way to take the size of the class.
Conceptual class sizes are not set in stone in any way, a type can be of
many different sizes based on its contents. Considering both "One String"
and "A much longer string that has alot of extra words in it" are both of
type string, how do you determine size just by passing string? The header,
etc size should be determinable, but I don't know how much value that would
have for you, as you should rarely, if ever, be messing with such things.
You can, if you are really interested in the size of a given object graph at
a given point in time serialize it and determine the length of the output.
This may be transient however because other objects can be added or removed
at any time, or it may be downright incorrect because some values are tossed
out during serialization.
Value Types, structs in C#, that have no managed type members can have their
size retreived using sizeof(type) in unsafe C# code, and are the suggested
choice for interop, etc. Note however that arrays in structs are managed
objects. C# 2.0 is slated to introduce a feature that allows for fixed sized
inline valuetype arrays, but that is not here yet.
"Jack" <ja**********@netscape.net> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Anybody know how to determine the "sizeof" a class?

TYIA

Jack

ja**********@netscape.NOSPAM.net

Nov 15 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by vijay | last post: by
18 posts views Thread by Tarundeep | last post: by
6 posts views Thread by dddddddd2444444@yahoo.co.uk | last post: by
6 posts views Thread by Laurent | last post: by
45 posts views Thread by charles.lobo@gmail.com | last post: by
11 posts views Thread by mast2as@yahoo.com | last post: by
6 posts views Thread by webinfinite@gmail.com | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.