Get class size of object

JS js.mdnq at gmail.com
Sun Aug 11 12:33:41 PDT 2013


On Sunday, 11 August 2013 at 19:06:07 UTC, Adam D. Ruppe wrote:
> On Sunday, 11 August 2013 at 18:33:19 UTC, JS wrote:
>> The code below does this, but at a cost of verbosity.
>
> I don't see what the difference is in functionality - it looks 
> to me that you just reimplemented what the compiler does 
> automatically with typeid.
>
> The way typeid(obj) works is similar to a virtual function call 
> internally, indeed, Class.vtbl[0] is a pointer to its TypeInfo 
> instance.
>
> But anyway, then the typesameinfo contains functions for the 
> class name and size, pretty similar to what you just did.
>
>
> What does your implementation give you that typeid() doesn't?

Well, I am wrapping the stuff. But when I've tried to do 
essentially l the same thing before using the compiler directly, 
it simply did not work.

If you read Simen Kjaeraas's post you will see it doesn't work 
directly with interfaces, which is what I was doing.

Hence, either a bug or anti-feature or whatever, the issue was 
with D and not some weird thing I was trying to do... All this 
nonsense is trying to work around D doing stupid stuff.

All I know is that in my code, when trying to get the actual 
object size, even if derived(which may change the size), I would 
always get 4. I was using an interface as my base type.

Regardless, there are now two solutions and I have to go back to 
my production code and figure out which one works best for my 
situation.



More information about the Digitalmars-d-learn mailing list