Static array initialisation

Imperatorn johan_forsberg_86 at hotmail.com
Thu Apr 1 06:22:43 UTC 2021


On Wednesday, 31 March 2021 at 17:27:44 UTC, DLearner wrote:
> Hi
>
> I did:
>    immutable uint  MemSize=100;  // Memory size in bytes.
>
> // Memory Pool
>    ubyte[MemSize]  MemPool = 8;
>
> And had a look in memory.
> I think the compiler set up 101 '8's, not 100 in memory.
>
> Which I did not expect.
>
> Best regards

It's a bit interesting though.

The behavior seems to vary a bit between compilers.

DMD:
ubyte[100] example.MemPool:
         db      008h,008h,008h,008h,008h,008h,008h,008h     
;........
         db      008h,008h,008h,008h,008h,008h,008h,008h     
;........
         db      008h,008h,008h,008h,008h,008h,008h,008h     
;........
         db      008h,008h,008h,008h,008h,008h,008h,008h     
;........
         db      008h,008h,008h,008h,008h,008h,008h,008h     
;........
         db      008h,008h,008h,008h,008h,008h,008h,008h     
;........
         db      008h,008h,008h,008h,008h,008h,008h,008h     
;........
         db      008h,008h,008h,008h,008h,008h,008h,008h     
;........
         db      008h,008h,008h,008h,008h,008h,008h,008h     
;........
         db      008h,008h,008h,008h,008h,008h,008h,008h     
;........
         db      008h,008h,008h,008h,008h,008h,008h,008h     
;........
         db      008h,008h,008h,008h,008h,008h,008h,008h     
;........
         db      008h,008h,008h,008h,000h,000h,000h,000h     
;........
         db      000h,000h,000h,000h,000h,000h,000h,000h     
;........

LDC:
ubyte[100] example.MemPool:
         .zero   100,8

GDC:
ubyte[100] example.MemPool:
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8
         .byte   8

As you can see, all have 100 valid values, but DMD seems to be 
aligning to a multiple.


More information about the Digitalmars-d-learn mailing list