Encouraging preliminary results implementing memcpy in D

Mike Franklin slavo5150 at yahoo.com
Fri Jun 15 00:15:35 UTC 2018


On Thursday, 14 June 2018 at 20:35:23 UTC, baz wrote:

> I asked on IRC yesterday and actually tHose memcpy are not the 
> memcpy we use to copy wide chunks, apparently it's rather for 
> an internal druntime thing, i.e cpy type to type so likely 
> always aligned.

Correct! D already has features like `a[] = b[]` so there is no 
reason to call `memcpy` directly; that is a job for the druntime. 
  `memcpyD` is intended to be an internal druntime utility.

However, we should still be good D citizens when we write our low 
level druntime code, so the interface will be `memcpy(T)(T a, T 
b)` and `memcpy(T)(T[] a, T[] b)` instead of `memcpy(void* a, 
void* b, size_t size)`.  This will ensure the code, at 
compile-time, adheres to D's guarantees such as `@safe`, 
`nothrow`, and `pure`.  And, given that it won't require 
`TypeInfo` it will be usable in -betterC.

Although rare, I believe it is still possible to have misaligned 
memory in D.  My understanding is that misaligned copies usually 
involve copying smaller chunks of the memory until they are 
aligned, and then copying the aligned memory in larger chunks.  I 
suspect that will work well with the D implementation.

TL;DR, Unaligned memory will be handled after optimized aligned 
memory copies are implemented.

Mike


More information about the Digitalmars-d-announce mailing list