Get class size of object

JS js.mdnq at gmail.com
Sun Aug 11 10:03:03 PDT 2013


On Sunday, 11 August 2013 at 16:43:09 UTC, Dicebot wrote:
> On Sunday, 11 August 2013 at 16:40:48 UTC, Maxim Fomin wrote:
>> Yes, this is answer to the question. By the way, it can be 
>> simply
>>
>> enum S = typeid(Whatever).init.length;
>
> If exact type is statically known, no ClassInfo is required:
>
> enum S = __traits(classInstanceSize, Whatever);

This is essentially what I'm doing BUT I am trying to avoid 
having to repeat the exact same crap in every class because it is 
time consuming, verbose, and error prone.



For those that care, here is a snippet of what I am doing. For 
those that are bitches, GTFO. Remember, I'm a troll so everything 
I say or do here is irrelevant, so I don't even know why you are 
reading this in the first place.

http://dpaste.dzfl.pl/d295bbbb


Note that because it is a function call it is extremely expensive 
compared to a compile time literal. Disassembly shows that the 
actual size is a constant so the vtabl lookup and a function call 
is all that is required. I'd like to minimize the overhead as 
much as possible and, ideally not have to manually add the 
template mixins to each class(it would be nice if it were 
automated). I'm trying to reduce the costs of RT lookup as much 
as possible(as I feel it is not necessary).







More information about the Digitalmars-d-learn mailing list