By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,007 Members | 979 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,007 IT Pros & Developers. It's quick & easy.

Size of a class

P: n/a
Anybody know how to determine the "sizeof" a class?

TYIA

Jack

ja**********@netscape.NOSPAM.net
Nov 15 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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.