www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - get size of class instance (not reference)?

reply Nick Sabalausky <SeeWebsiteToContactMe semitwist.com> writes:
These just give me the size of a *reference* to the class:

class Foo {...}
Foo.sizeof
typeid(Foo).tsize

How can I get the size of a non-subclassed *instance*?
Feb 25 2013
parent reply "bearophile" <bearophileHUGS lycos.com> writes:
Nick Sabalausky:

 How can I get the size of a non-subclassed *instance*?
Is this enough? http://dlang.org/traits.html#classInstanceSize Bye, bearophile
Feb 25 2013
parent reply Nick Sabalausky <SeeWebsiteToContactMe semitwist.com> writes:
On Tue, 26 Feb 2013 01:54:44 +0100
"bearophile" <bearophileHUGS lycos.com> wrote:

 Nick Sabalausky:
 
 How can I get the size of a non-subclassed *instance*?
Is this enough? http://dlang.org/traits.html#classInstanceSize
Ahh, yes, of course. I had a feeling I was overlooking something obvious. Thanks.
Feb 25 2013
parent "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Mon, 25 Feb 2013 20:09:05 -0500, Nick Sabalausky  
<SeeWebsiteToContactMe semitwist.com> wrote:

 On Tue, 26 Feb 2013 01:54:44 +0100
 "bearophile" <bearophileHUGS lycos.com> wrote:

 Nick Sabalausky:

 How can I get the size of a non-subclassed *instance*?
Is this enough? http://dlang.org/traits.html#classInstanceSize
Ahh, yes, of course. I had a feeling I was overlooking something obvious. Thanks.
ClassInfo also has an init property which is a block of memory that is the default data in the class. This is what druntime uses when allocating a class. This would work to get the derived type length as well. -Steve
Feb 26 2013