ldc 0.9.1 released

Frits van Bommel fvbommel at REMwOVExCAPSs.nl
Wed May 27 15:27:12 PDT 2009


bearophile wrote:
> While this code:
> 
>     typedef int Int2 = 2;
>     auto a = cast(int[])(new Int2[1000]);
>     
> Produces:
> 
> 	pushl	%esi
> 	subl	$8, %esp
> 	movl	$1000, 4(%esp)
> 	movl	$_D20TypeInfo_ATmain4Int26__initZ, (%esp)
> 	xorl	%esi, %esi
> 	call	_d_newarrayiT
> 	movl	%esi, %ecx
> 	
> (I haven't taken the running time, so I don't know if this idiom is more efficient with LDC).

For arrays that escape, it's quite probably more efficient since it only gets 
initialized once this way.
For arrays that can get stack-promoted it may not be, because (non 
zero-)initialized arrays aren't eligible for that yet (as you can tell by the 
_d_newarray* call, which GC-allocates a new array and initializes it). So which 
is more efficient in that case depends on whether a GC allocation is more 
expensive than re-initializing 4 KB of data.


More information about the Digitalmars-d-announce mailing list