Allocating a class within another class during object init w/o passing in an allocator

David Zhang via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Dec 15 13:37:34 PST 2016


On Thursday, 15 December 2016 at 21:08:51 UTC, ag0aep6g wrote:
> On 12/15/2016 09:51 PM, David Zhang wrote:
>> However, it leaves me with another question, how
>> much (if any) space would the static array require from the 
>> class?
>
> Depends on SomeClass. The array's size is just the value of 
> __traits(classInstanceSize, SomeClass). There's no overhead.
>
> You can print such stuff at compile time with pragma(msg, ...):
>
> ----
> pragma(msg, __traits(classInstanceSize, SomeClass));
> pragma(msg, Foo.scStorage.sizeof); /* same */
> ----

So the size of Foo would be the size of SomeClass plus members? 
ie. Is the size of the array stored too?


More information about the Digitalmars-d-learn mailing list