473,327 Members | 1,979 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Size of a class

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

TYIA

Jack

ja**********@netscape.NOSPAM.net
Nov 15 '05 #1
2 4080
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

35
by: wired | last post by:
Hi, I've just taught myself C++, so I haven't learnt much about style or the like from any single source, and I'm quite styleless as a result. But at the same time, I really want nice code and I...
4
by: vijay | last post by:
I have a doubt with size of classed with virtual functions I have declared A,A1,A2 ,B , C, D some classes with no varaibles but a vitual function each, The size of A is as expected 4 bytes with...
18
by: Tarundeep | last post by:
hi, let us say it is a 32 bit processor then the size of the pointer is 32 bits. now i want to know what would be the size of the class with vtable pointer in it , that is it has few virtual...
3
by: ThazKool | last post by:
Is there anyway to write a class or struct that has no storage. It only operates on a reference to an already existing type. This is actually an extension to another thread. The thread went a...
6
by: dddddddd2444444 | last post by:
Hi,please help... It works fine when I define a 2-D array like char code. But it won't work when I try to define the array dynamically using a function. It just crashes. Does anyone know why?...
6
by: Laurent | last post by:
Hello, This is probably a dumb question, but I just would like to understand how the C# compiler computes the size of the managed structure or classes. I'm working on this class: public...
45
by: charles.lobo | last post by:
Hi, I have recently begun using templates in C++ and have found it to be quite useful. However, hearing stories of code bloat and assorted problems I decided to write a couple of small programs...
18
by: Diogenes | last post by:
Hi All; I, like others, have been frustrated with designing forms that look and flow the same in both IE and Firefox. They simply did not scale the same. I have discovered, to my chagrin,...
11
by: mast2as | last post by:
This question has been posted to this forum before and I read the thread but found that the answers were perhaps imcomplete, so I am trying again. Whenever I am creating objects I would like to...
6
by: webinfinite | last post by:
Hi, How to find a STL class size, for example: string. I would like to know what the size of the implementation of this class, I am not interested in the size of its object but the class itself....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.