size of a class instance

Bill Baxter dnewsgroup at
Tue Nov 14 18:29:23 PST 2006

Sean Kelly wrote:
> Bill Baxter wrote:
>> I guess when it comes down to it, finding the size of a class is 
>> really only useful for satisfying one's curiosity and optimizing 
>> member orders to get better alignment.  And for that purpose I guess 
>> it doesn't really have to be that intuitive a name.
> But the existing method only works at run time, which doesn't allow for 
> things like this:
>     byte[MyClass.isizeof] buf;
>     MyClass c = new(&buf[0]) MyClass();
>     scope(exit) delete c;
> Evil, I know, but it kind of stinks that alloca is the only means we 
> currently have to construct classes on the stack.

Oh yeh.  Forgot about the runtime only thing.  So I'll change my tune 
to: if classinfo.init.length were available at runtime *then* it would 
be good enough.

But I presume making that so is not much easier than adding isizeof.  If 
it were easy, then classinfo.init.length wouldn't have had the runtime 
restriction to begin with.


More information about the Digitalmars-d-learn mailing list