Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is serial copy? And why it is implemented like this?

What is serial copy? Is it different from deep-copy and shallow-copy?

According to the wiki entry under Duff's device, it is traditionally implemented as:

do {                //count > 0 assumed
    *to = *from++;  //Note that the 'to' pointer is NOT incremented
} while(--count > 0);

And then it makes a note, saying

Note that to is not incremented because Duff was copying to a single memory-mapped output register.

I didn't really understand this note.

If to pointer is not incremented, then what is the point of the loop? Why then it is implemented as:

*to = from[count-1]; //does it not do the same thing?

I suspect that it has something to do with the definition of serial copy.

How can we allocate memory for to so that the loop would make some difference?

like image 497
Nawaz Avatar asked Nov 17 '11 09:11

Nawaz


1 Answers

The point of such a copy is that it is not made to normal memory, but to a serial register.

So, each time a write is made to the address of the register (to), the hardware associated with the register will do something like send the bits over a serial link, or push them onto a queue for some other hardware to deal with.

Typically you cannot even read from register addresses like this, so they are very unlike normal memory, and best thought of as an interface to a particular piece of hardware that just happens to be located at a memory address.

like image 58
James Avatar answered Sep 18 '22 10:09

James