On 04/08/2014 02:35 PM, Mike wrote:
On Tuesday, 8 April 2014 at 11:56:43 UTC, ketmar wrote:
I understand that. But why is dest[] = src[] not good enough for
run-time?
'cause some compilers (gcc, for example) has memcpy() as 'intrinsic'
and generates better inline code for it sometimes. it's just a small
hint for compiler backend, and faster code is good, isn't it? ;-)
a[] = b[] causes the compiler to generate a call to _d_arraycopy, and
_d_arraycopy calls, you guessed it, memcpy! (verified with GDC 4.8.2)
So, there is no performance benefit calling memcpy directly. It's going
to be called anyway.
_d_arraycopy does check if the source and destination are of equal
length and that they don't overlap before calling memcpy.
Although i don't know how much that impacts the performance.
I'm beginning to believe that, at least in the code I posted, memcpy can
be replaced by the array syntax, removing a dependency on the C library.
--
Mike Wey