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

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

According to the wiki entry in the Duff 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 he takes a note, saying

Note that to does not increase because Duff copied to a single output disk with memory mapping.

I did not quite understand this note.

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

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

I suspect it has something to do with defining a serial copy.

How can we allocate memory for to so that the loop has some meaning?

+6
source share
3 answers

The point of such a copy is that it does not go to ordinary memory, but to the serial register.

So, every time a record is written to the register address ( to ), the hardware associated with the register will do something like send bits via a serial link or click on the queue for some other hardware to work with.

As a rule, you cannot even read register addresses like this, therefore they are very different from ordinary memory and are best perceived as an interface to a specific piece of equipment that is simply located at the memory address.

+9
source

http://en.wikipedia.org/wiki/Memory-mapped_I/O#Example

Some platforms have special addresses that, when you read / write to it, the system will perform some I / O operations. For example, to may be the address that controls the speaker during recording. In this case, the loop will, for example, be able to reproduce the sound, and *to = from[count-1]; will not give any useful solution.

+4
source

The to pointer here is "special." On certain equipment, you can access I / O ports by writing them to special areas of memory. If you want to send a bit pattern through an I / O port where the pattern was already in memory, this is what you do.

Each entry in to causes a normal change in the output from the I / O port. This is for iterating over a template and writing it to a "special" memory.

How you access such โ€œspecialโ€ memory is very specific to the platform and implementation. Sometimes itโ€™s just a matter of always writing to a fixed address - usually some platform header provides #define or similar to make this information available to you at compile time. Sometimes there is a system call that you need to make so that it indicates the address on which a particular device is configured.

+2
source

Source: https://habr.com/ru/post/901704/


All Articles