www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Error: overlapping array copy

reply Ant <duitoolkit yahoo.ca> writes:
Walter,

are you realy not going to code the overlapping array copy?
Why? seems so simple...
how many picoseconds are spend to check from which to to start the copy?

I just got the exception "Error: overlapping array copy".

Ant
Nov 18 2004
next sibling parent reply "Simon Buchan" <currently no.where> writes:
On Thu, 18 Nov 2004 21:24:40 -0500, Ant <duitoolkit yahoo.ca> wrote:

 Walter,

 are you realy not going to code the overlapping array copy?
 Why? seems so simple...
 how many picoseconds are spend to check from which to to start the copy?

 I just got the exception "Error: overlapping array copy".

 Ant

If you think (or know) that an array copy is going to overlap, why not just copy to a temp first? The end result is the same, and its a heck of a lot easier to implement and optimise. (Wasn't there some thing about thread safety? Haven't used threads, couldn't say) -- Using Opera's revolutionary e-mail client: http://www.opera.com/m2/
Nov 18 2004
next sibling parent Ant <Ant_member pathlink.com> writes:
In article <opsho5hlo0jccy7t simon.homenet>, Simon Buchan says...
If you think (or know) that an array copy is going to overlap, why not
just copy to a temp first? The end result is the same, and its a heck of
a lot easier to implement and optimise. (Wasn't there some thing about
thread safety? Haven't used threads, couldn't say)

I could take that argument, streach it, expanded it and ending up programming in assembler! probably there is a good reason (I hope) not to implement overlapping array copy but that reason has nothing to do with the concept of arrays. I have my Array template class where I have implemented it, with the recent fixes to the type info I can probably start using it. I don't make this suggestiong because I'm lazy but because I think it's the right thing. (reading this back sounds rispid, it's not my intention, just can't do better) Ant
Nov 19 2004
prev sibling parent "Lionello Lunesu" <lionello.lunesu crystalinter.remove.com> writes:
You don't always need a complete copy of the array. An overlapping array 
copy just has to be a little smarter, a little more careful.

Something like this will most likely work (assuming it does a 
for(x=0;x<len;x++) ):

memcpy( array, array+10, len );

It's the other case that needs care:

memcpy( array+10, array, len ); // len>10 causes problems

Nothing a smart compiler can't fix. For example, starting at the last 
element and going back would be one way to copy the array without the need 
of a temporary copy (Although the CPU cache will probably not like it).

Lionello.

"Simon Buchan" <currently no.where> wrote in message 
news:opsho5hlo0jccy7t simon.homenet...
 On Thu, 18 Nov 2004 21:24:40 -0500, Ant <duitoolkit yahoo.ca> wrote:

 Walter,

 are you realy not going to code the overlapping array copy?
 Why? seems so simple...
 how many picoseconds are spend to check from which to to start the copy?

 I just got the exception "Error: overlapping array copy".

 Ant

If you think (or know) that an array copy is going to overlap, why not just copy to a temp first? The end result is the same, and its a heck of a lot easier to implement and optimise. (Wasn't there some thing about thread safety? Haven't used threads, couldn't say) -- Using Opera's revolutionary e-mail client: http://www.opera.com/m2/

Nov 19 2004
prev sibling parent reply "Walter" <newshound digitalmars.com> writes:
"Ant" <duitoolkit yahoo.ca> wrote in message
news:cnjlnm$p8u$1 digitaldaemon.com...
 Walter,

 are you realy not going to code the overlapping array copy?
 Why? seems so simple...
 how many picoseconds are spend to check from which to to start the copy?

 I just got the exception "Error: overlapping array copy".

There are a number of potential optimizations that can be done on array operations if they don't overlap. I want to leave the door open for them.
Nov 19 2004
parent reply Ant <Ant_member pathlink.com> writes:
In article <cnljdb$ofj$1 digitaldaemon.com>, Walter says...
"Ant" <duitoolkit yahoo.ca> wrote in message
 I just got the exception "Error: overlapping array copy".

There are a number of potential optimizations that can be done on array operations if they don't overlap. I want to leave the door open for them.

But I don't understand, can't you first check if there is an overlap and then use the optimized code or not depending on that? From my point of view it seems very simple to do. How many clock cycles takes to check for the overlap? I don't mind loosing those to have consistency on the array copy. The responsability to check for overlapping is passed to the D code it's not removed. anyway if the exception is thrown the check is already there. Arrays limitation (this an others) will force us to have a template class for arrays. Ant
Nov 19 2004
parent reply "Walter" <newshound digitalmars.com> writes:
"Ant" <Ant_member pathlink.com> wrote in message
news:cnlmu8$tln$1 digitaldaemon.com...
 In article <cnljdb$ofj$1 digitaldaemon.com>, Walter says...
"Ant" <duitoolkit yahoo.ca> wrote in message
 I just got the exception "Error: overlapping array copy".

operations if they don't overlap. I want to leave the door open for them.

But I don't understand, can't you first check if there is an overlap and then use the optimized code or not depending on that?

Yes, that can work. But since overlapping copies are relatively rare, it's fairly expensive.
 From my point of view it seems very simple to do.
 How many clock cycles takes to check for the overlap?

4 fetches, 2 adds, 2 compares, and register pressure. A lot of benchmarks tend to focus on these kinds of things, and D can't afford to get a reputation for being slow.
 I don't mind loosing those to have consistency on the array copy.
 The responsability to check for overlapping is passed to the D code
 it's not removed.
 anyway if the exception is thrown the check is already there.

The checks are removed for release builds.
 Arrays limitation (this an others) will force us to have a template
 class for arrays.

memmove() will work, and will be a strong indicator in the code that an overlapping copy is being done.
Nov 19 2004
parent Ant <duitoolkit yahoo.ca> writes:
On Fri, 19 Nov 2004 14:09:06 -0800, Walter wrote:

 
 "Ant" <Ant_member pathlink.com> wrote in message
 But I don't understand,
 can't you first check if there is an overlap and then use the optimized
 code or not depending on that?

Yes, that can work. But [...]

thanks for the full explanation! now I understant, I don't agree but I understand.
 memmove() will work, and will be a strong indicator in the code that an
 overlapping copy is being done.

will use it. Ant
Nov 19 2004