Large .init for class containing void-initialized struct

Basile B. via Digitalmars-d digitalmars-d at puremagic.com
Wed Dec 7 02:56:44 PST 2016


On Wednesday, 7 December 2016 at 08:46:13 UTC, Ali Çehreli wrote:
> On 12/06/2016 06:10 PM, Basile B. wrote:
> > On Wednesday, 7 December 2016 at 00:20:11 UTC, Ali Çehreli
> wrote:
> >> tl;dr; go to the TLDR section below. :)
> >>
> >> [...]
> >>
> >> struct S {
> >>     int i = void;
> >>     double d = void;
> >>     ubyte[10_000] a = void;
> >> }
> >>
> >> class C {
> >>     S s = void; // (Same result even without the =void)
> >> }
> >>
> >> void main() {
> >> }
> >>
> >> [...]
> >> 0000000004446260 0000000000003633 T
> >> _D4core4time8Duration13_toStringImplMxFNaNbNfZAya
> >> 0000000004505140 0000000000003707 T _d_arraysetlengthiT
> >> 0000000006681456 0000000000010032 V _D6deneme1C6__initZ
> >>
> >> Now we have a 10032 byte C.init.
> >>
> >> Is there a rationale for this or is this an implementation
> quality
> >> issue? Is there a bug already? I could not find one.
> >>
> >> Also, I failed to find the "= void" documentation e.g. not
> on the
> >> struct spec page.
> >>
> >> Thank you,
> >> Ali
> >
> > Non initialized classes just don't work. Because of the
> hidden classes
> > fields an initializer is **always** needed. What happens in
> your example
> > is that the initializer size is sub optimal.

I've said bullshit here. In case of manual init, gaps couldn't be 
handled easily anyway. We have the aggregate size, we have a 
pointer to its initializer, that's all.

>
> Understood. Please confirm whether the following is a bug. Just 
> because a class uses a *pointer* to a void-initialized struct, 
> the struct gets a .init:
>
> struct MyStruct(T) {
>     T[10_000] a = void;
> }
>
> // Same with struct
> class Outer {
>     MyStruct!ubyte* s;
> }
>
> void main() {
> }
>
> 0000000006681728 0000000000010000 V 
> _D6deneme15__T8MyStructThZ8MyStruct6__initZ
>
> Make the struct a non-template and MyStruct.init disappears as 
> expected.
>
> Ali

I wouldn't say it's a bug rather an enhancement request. 
Unfortunately with my expertise level I can't say more. I think 
that one of the GDC member expressed some interest into making 
initialization of aggregates better. It was when A.Alexandrescu 
worked on RCString, I can't find the link anymore, it was about 
RCString init being slow, in comparison to a cpp equivalent.

It looks like this discussion is highly related.


More information about the Digitalmars-d mailing list