Sizeof class instance

Daniel Keep daniel.keep.lists at gmail.com
Sat Oct 3 21:07:42 PDT 2009



Jarrett Billingsley wrote:
> On Sat, Oct 3, 2009 at 5:50 PM, Justin Johansson <no at spam.com> wrote:
>> How does one determine the sizeof (in bytes) of an instance of a class in D?
>>
>> .sizeof works as advertised for structs, but for reference types,
>> .sizeof yields the sizeof the referencing variable (effectively same as size of a pointer)
>> and not the size of the underlying instance.
>>
>> I did try scanning the NG and read spec_D1.00.pdf.  Perhaps I missed it in the latter.
>>
>> btw. I was poking under the hood of std.xml and though, wow, instances of Element
>> class look humongous, and so I'm interested to how exactly how humongous.
>>
>> Thanks for all help.
>> Justin
> 
> There's no way to get it at compile-time in D1. The best you can do is
> Class.classinfo.init.length.

What nonsense, of course there is!

http://gist.github.com/140531

Note: this is VERY old code, but I have no reason to think it won't
still work.  I may need a little dusting off...


More information about the Digitalmars-d-learn mailing list