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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With