array copy/ref question
Jarrett Billingsley
kb3ctd2 at yahoo.com
Mon Aug 11 21:28:46 PDT 2008
"Brian Sturk" <bsturk at comcast.net> wrote in message
news:g7qoh0$2vvr$1 at digitalmars.com...
> Lars Ivar Igesund Wrote:
>
>> Brian Sturk wrote:
>>
>> > I'm trying to get a handle on the array assignment, slicing operations
>> > and
>> > am a little confused. The last copy gives me an "overlapping array
>> > copy".
>> > Both arrays have a length of 4. Is it that I cannot copy from one
>> > dynamic array to another (even if the same size)?
>>
>> It means you are trying to copy from the same memory you are copying to -
>> your arrays reference the same memory.
>
> Hi there,
>
> Thanks for the clarification, sounds like I need to do a memcpy to do a
> true copy.
Nope, it's memmove you're looking for. memcpy over overlapping memory
regions has undefined behavior. Incidentally, for the same reasons
overlapping slice copies are illegal -- to allow for the use of faster
hardware copies that disallow overlapping regions.
More information about the Digitalmars-d
mailing list