Initializing static arrays without specifying size

bearophile bearophileHUGS at lycos.com
Mon Aug 2 10:04:39 PDT 2010


BCS:
> Is that with or without inline? If that doesn't inline away to a memcopy 
> then it looks like an optimization opportunity to me.

That's with inline, but if you don't use inline the result is the same, because that is the asm of a function, not of its caller (the main), so DMD keeps the not inlined function around anyway even when it inlines it. So in your binary you find all the staticArray() you have instantiated/used.

This is the main (compiled with -O -release -inline, dmd 2.047):

__Dmain comdat
L0:     sub ESP,0194h
        push    0190h
        push    03DEh
        push    03D4h
        push    03CAh
        push    03C0h
        push    03B6h
        push    03ACh
        push    03A2h
        push    0398h
        push    038Eh
        push    0384h
        push    037Ah
        push    0370h
        push    0366h
        push    035Ch
        push    0352h
        push    0348h
        push    033Eh
        push    0334h
        push    032Ah
        push    0320h
        push    0316h
        push    030Ch
        push    0302h
        push    02F8h
        push    02EEh
        push    02E4h
        push    02DAh
        push    02D0h
        push    02C6h
        push    02BCh
        push    02B2h
        push    02A8h
        push    029Eh
        push    0294h
        push    028Ah
        push    0280h
        push    0276h
        push    026Ch
        push    0262h
        push    0258h
        push    024Eh
        push    0244h
        push    023Ah
        push    0230h
        push    0226h
        push    021Ch
        push    0212h
        push    0208h
        push    01FEh
        push    01F4h
        push    01EAh
        push    01E0h
        push    01D6h
        push    01CCh
        push    01C2h
        push    01B8h
        push    01AEh
        push    01A4h
        push    019Ah
        push    0190h
        push    0186h
        push    017Ch
        push    0172h
        push    0168h
        push    015Eh
        push    0154h
        push    014Ah
        push    0140h
        push    0136h
        push    012Ch
        push    0122h
        push    0118h
        push    010Eh
        push    0104h
        push    0FAh
        push    0F0h
        push    0E6h
        push    0DCh
        push    0D2h
        push    0C8h
        push    0BEh
        mov EAX,offset FLAT:_D14TypeInfo_G100i6__initZ
        push    0B4h
        push    0AAh
        push    0A0h
        push    096h
        push    08Ch
        push    082h
        push    078h
        push    06Eh
        push    064h
        push    05Ah
        push    050h
        push    046h
        push    03Ch
        push    032h
        push    028h
        push    01Eh
        push    014h
        push    0Ah
        push    0
        push    064h
        push    EAX
        call    near ptr __d_arrayliteralT
        add ESP,0198h
        push    EAX
        lea ECX,0Ch[ESP]
        push    ECX
        call    near ptr _memcpy
        mov EDX,offset FLAT:_DATA
        push    dword ptr 018h[ESP]
        push    EDX
        call    near ptr _printf
        add ESP,014h
        add ESP,0194h
        xor EAX,EAX
        ret

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list