copying memory in phobos
monarch_dodra
monarchdodra at gmail.com
Wed Apr 9 01:32:37 PDT 2014
On Wednesday, 9 April 2014 at 08:24:55 UTC, Mike wrote:
> On Tuesday, 8 April 2014 at 14:59:35 UTC, Artur Skawina wrote:
>> '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.
>
> Then it could do such magic in the _d_arraycopy function where
> the call to memcpy exists. I'm still not seeing the motivation
> behind putting this call to memcpy in Phobos.
Depending on the type being copied, "a[] = b[]" is not straight
up "memory copy" it's the actual full assignment, with postblit
and all. That's why the call we want is *really* memcpy.
The code where you saw this, if I'm not mistaken, is
"inPlaceInsert" or something of the like. The idea in this code
is to actually *move* the data, not create *copies* elsewhere.
The array assign is a fallback for CTFE. It's fine in CTFE,
because we don't care about performance, but it's not the actual
call we want.
More information about the Digitalmars-d-learn
mailing list