Replacing C's memcpy with a D implementation

Adam D. Ruppe destructionator at gmail.com
Sun Jun 10 13:16:21 UTC 2018


On Sunday, 10 June 2018 at 12:49:31 UTC, Mike Franklin wrote:
> D utilizes from the C library with D implementations.  There 
> are many reasons to do this, one of which is to leverage 
> information available at compile-time and in D's type system 
> (type sizes, alignment, etc...) in order to optimize the 
> implementation of these functions, and allow them to be used 
> from @safe code.

So keep in mind that memcpy is really a magical intrinsic anyway 
and optimzers frequently don't actually call a function, but 
rather see the size and replace the instructions inline (like it 
might replace it with just a couple movs instead of something 
fancy).

And D already has it built in as well for @safe etc:

arr1[] = arr2[]; // the compiler makes this memcpy, the optimzer 
can further do its magic

so be sure to check against that too.




More information about the Digitalmars-d mailing list