copying memory in phobos

Artur Skawina art.08.09 at gmail.com
Tue Apr 8 07:59:19 PDT 2014


On 04/08/14 14:35, 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.

'memcoy' being a built-in compiler intrinsic means that when the compiler
sees a 'memcpy' call, it does some checks (eg is the length statically
known and small enough?) and then can generated the copy instructions
directly, instead of calling the lib function.

artur


More information about the Digitalmars-d-learn mailing list