Sizeof class instance
none at example.net
Sun Oct 4 02:56:15 PDT 2009
Justin Johansson wrote:
> grauzone Wrote:
>> Justin Johansson 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.
>> As Jarrett said, x.classinfo.init.length is the simplest way in D1.
>>> I did try scanning the NG and read spec_D1.00.pdf. Perhaps I missed it in the latter.
>> I guess that PDF is horribly outdated, although it may work for some
>>> 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.
>> Wasn't std.xml for D2? Anyway, last what I remember is that std.xml is
>> unmaintained, slow, buggy, and shouldn't be seriously used.
> Yes and yes. I'm currently using D1 but with view to D2 am having a peek at it's libs.
> I can see why std.xml in D2 is slow, and would not be surprised if buggy as well; it is quite disgusting code that's been hacked together without any real rhyme or reason. So guess I'll be writing my own stuff
> and leveraging on C libs where possible. Got Expat parser running with D without too much trouble.
In case you didn't know, Tango's XML parser is said to be even faster
than other commonly used XML parsers in C/Java:
> Thanks for comment grauzone.
> -- Justin Johansson
More information about the Digitalmars-d-learn