On Thu, Oct 25, 2012 at 12:05:25AM +0200, Era Scarecrow wrote: > On Wednesday, 24 October 2012 at 15:39:19 UTC, thedeemon wrote: > >The code DMD generates for initializing the struct does not use > >loops, so it's > >xor ecx, ecx > >mov [eax], ecx > >mov [eax+4], ecx > >mov [eax+8], ecx > >... > > > >So your code creates a lot of work for the compiler. > > That seems silly. I would think after the struct's init/contents > were known it would make a single block that holds the basic init > for it and bulk copy every time it needed it (if it's beyond a > certain size, say 32 bytes). > > Also memset only works if the data can be defaulted to 0. Hmmm...
Not true. Memset is *usually* used to set memory to 0, but it can set memory to other byte values too. Although this doesn't help if the .init value isn't something consisting of repeated byte values. In any case, though, separately initializing every member of an array is silly. That's what a loop is for. That, or a memcpy from an immutable copy of .init. T -- Life would be easier if I had the source code. -- YHL