www.digitalmars.com         C & C++   DMDScript  

D - Size of a class

reply "Dario" <supdar yahoo.com> writes:
How can I find the size of a class?
"Object o; return o.size;" doesn't work. It returns the size of the
reference.
A '.length' field in ClassInfo would be useful (or a '.length' property for
classes).

I need this because I would like to write a function which returns a byte[]
which contains the contents of the class.
We'd have to decide if that variable should include the classinfo pointer
and the "monitor" (what is this "monitor" exactly?).
Oct 18 2003
next sibling parent "Sean L. Palmer" <palmer.sean verizon.net> writes:
Can't you do "Object.size" ?

That's the problem with references. IMO they should act as if they actually
*are* the object they refer to, in all respects except assignment.  I would
expect your example "Object o; return o.size;" to return the same thing as
"return Object.size;"

There are a whole bunch of things that would be nice to have in the
ClassInfo...

Sean

"Dario" <supdar yahoo.com> wrote in message
news:bmrc5d$16c3$2 digitaldaemon.com...
 How can I find the size of a class?
 "Object o; return o.size;" doesn't work. It returns the size of the
 reference.
 A '.length' field in ClassInfo would be useful (or a '.length' property
for
 classes).
Oct 18 2003
prev sibling parent reply "Walter" <walter digitalmars.com> writes:
"Dario" <supdar yahoo.com> wrote in message
news:bmrc5d$16c3$2 digitaldaemon.com...
 How can I find the size of a class?
 "Object o; return o.size;" doesn't work. It returns the size of the
 reference.
 A '.length' field in ClassInfo would be useful (or a '.length' property
for
 classes).

 I need this because I would like to write a function which returns a
byte[]
 which contains the contents of the class.
 We'd have to decide if that variable should include the classinfo pointer
 and the "monitor" (what is this "monitor" exactly?).
The size of a class can be obtained from: Object foo; foo.classinfo.init.length;
Oct 19 2003
parent "Dario" <supdar yahoo.com> writes:
Walter:
 The size of a class can be obtained from:
     Object foo;
     foo.classinfo.init.length;
Thanks!
Oct 20 2003